# -*- coding: utf-8 -*-
import os
import time
import random
from operator import truediv
from turtledemo.penrose import start

from  . import  JiangHu


class Carry(JiangHu.JiangHu):
    def __init__(self, thread_id, name, index, public_data,ignore_block):
        super().__init__(thread_id, name, index, public_data,ignore_block)
        self.log.info("xxxxx1")

    @staticmethod
    def MakeArmStr(armList, addOneList):
        for i in addOneList:
            for index in range(len(armList)):
                if i in armList[index]:
                    armList.insert(index+1,r"装备\普通%s.bmp"%i)
                    break
        return armList

    def first_init(self):
        self.publicData["游戏线程大漠插件是否绑定"] = 0
        self.publicData["人物不在黄陵次数"] = 0

        self.publicData["是否进船坞"] = 0
        if self.publicData["系统"]["次要阶段"] == 0 or self.publicData["系统"]["次要阶段"] == "":
            self.publicData["系统"]["次要阶段"] = 1


        self.data["+1装备列表"] = ["玄铁重剑", "屠龙刀", "离别钩", "倚天剑", "圆月弯刀", "阴阳剑", "梅花枪",
                                   "碧血照丹青", "金蛇锥", "青菱扇", "圣火令", "三绝拐", "五行旗", "银丝手套",
                                   "霸王胄"]

        self.data["装备优先顺序列表"]=self.LoadCustomConf(r"conf\%s.yaml"%self.publicData["装备配置"],r"装备")
        tmp=dict()
        xx=0
        for i in self.data["装备优先顺序列表"]:
            tmp[i]=xx
            xx+=1

        self.data["装备优先顺序字典"] =tmp
        # dict(zip(self.data["装备优先顺序列表"], range(len(self.data["装备优先顺序列表"]))))
        self.data["第一次+1装备选择列表"]= "|".join(self.MakeArmStr(self.data["装备优先顺序列表"][:self.publicData["主c"]["装备刷新阈值"]],self.data["+1装备列表"] ))
        self.data["+1装备选择列表"] = "|".join(self.MakeArmStr(self.data["装备优先顺序列表"],self.data["+1装备列表"] ))
        self.data["重铸选择列表"] = "|".join( self.data["装备优先顺序列表"])
        # self.publicData["装备重铸选择配置"] = self.publicData["重铸列表"]
        # check 会修改
        self.data["是否在高昌"] = False
        self.data["奇遇前准备完成"] = False
        self.data["高昌"]={
            "1":False,
            "2":False,
            "3":False,
            "4":False,
        }
        self.data["防御塔存在"] = True
        self.data["帐篷是否存在"] = True
        self.data["是否卡丹"] = False
        self.data["武学境界"] = 0
        self.data["绝世神兵1"] = self.dm.GetDirPath(r"pic\绝世神兵\1")
        self.data["绝世神兵2"] = self.dm.GetDirPath(r"pic\绝世神兵\2")
        self.data["绝世神兵3"] = self.dm.GetDirPath(r"pic\绝世神兵\3")

        tmp=self.publicData["主c"]["洗髓经残页"]
        self.data["需要的洗髓经残页"]=[]
        for x in tmp.split(","):
            self.data["需要的洗髓经残页"].append(r"主线\洗髓经\%s%s.bmp"%(self.publicData["主c"]["洗髓经残页品质"],x))
        self.data["需要r洗髓经残页位置"] = [1, 2, 3, 4, 5]
        # 需要缓存到本地

        self.data["洗髓经当前等级"] = 0
        self.data["最近一次吃书"]=0.0
        self.data["最近一次拿宝石"] = 0.0
        self.data["R技能挑战次数"] = 0
        self.data["最近一次解锁10"] = 0.0
        self.data["仓库上品书"] = [
            r"书\仓库6上采燕功.bmp", r"书\仓库6上蜀道难牌法.bmp", r"书\仓库6上心意气混元功.bmp", r"书\仓库6红三光奇功.bmp",
            r"书\仓库7上地火功.bmp", r"书\仓库7上袈裟伏魔功.bmp", r"书\仓库7上金雁功.bmp", r"书\仓库7上控鹤功.bmp", r"书\仓库7上释迦掷象功.bmp", r"书\仓库7红七煞断脉封穴法.bmp",
            r"书\仓库9上大力鹰抓功.bmp", r"书\仓库9上闭穴功.bmp", r"书\仓库9上泥鳅功.bmp", r"书\仓库9红圣心诀.bmp"
        ]
        self.data["仓库上品书路径"] = self.dm.GetPicAbsPath("|".join(self.data["仓库上品书"]))

        self.data["上品书"] = [
            r"书\6上采燕功.bmp",r"书\6上蜀道难牌法.bmp",r"书\6上心意气混元功.bmp",r"书\6红三光奇功.bmp",
            r"书\7上地火功.bmp",r"书\7上袈裟伏魔功.bmp",r"书\7上金雁功.bmp",r"书\7上控鹤功.bmp",r"书\7上释迦掷象功.bmp",r"书\7红七煞断脉封穴法.bmp",
            r"书\9上大力鹰抓功.bmp",r"书\9上闭穴功.bmp",r"书\9上泥鳅功.bmp",r"书\9红圣心诀.bmp"
        ]
        self.data["上品书路径"] = self.dm.GetPicAbsPath("|".join(self.data["上品书"]))

        if self.publicData["主c"]["玄铁离别立即认主"]:
            for i in self.publicData["主c"]["主动重铸列表"]:
                if "玄铁重剑" in i or "离别" in i:
                    del self.publicData["主c"]["主动重铸列表"][i]
        self.data["任务"] = {

            "10": [
                r"书\10红摩诃无量.bmp", r"书\10红赤火神功.bmp", r"书\10红混天四绝.bmp",
                r"书\10上枯荣禅功.bmp", r"书\10上擒龙功.bmp", r"书\10上紫霞功.bmp",
                r"书\10上炎炎功.bmp", r"书\10上铁指诀.bmp", r"书\10上狮子吼.bmp",
                r"书\10上狂风迅雷功.bmp", r"书\10上真武七截阵.bmp", r"书\10上银索金铃索法.bmp",],
            "10全": [
                r"书\10红摩诃无量.bmp", r"书\10红赤火神功.bmp", r"书\10红混天四绝.bmp",
                r"书\10上枯荣禅功.bmp", r"书\10上擒龙功.bmp", r"书\10上紫霞功.bmp",
                r"书\10上炎炎功.bmp", r"书\10上铁指诀.bmp", r"书\10上狮子吼.bmp",
                r"书\10上狂风迅雷功.bmp", r"书\10上真武七截阵.bmp", r"书\10上银索金铃索法.bmp",
                r"书\10中枯荣禅功.bmp", r"书\10中擒龙功.bmp", r"书\10中紫霞功.bmp",
                r"书\10中炎炎功.bmp", r"书\10中铁指诀.bmp", r"书\10中狮子吼.bmp",
                r"书\10中狂风迅雷功.bmp", r"书\10中真武七截阵.bmp", r"书\10中银索金铃索法.bmp",
                r"书\10下枯荣禅功.bmp", r"书\10下擒龙功.bmp", r"书\10下紫霞功.bmp",
                r"书\10下炎炎功.bmp", r"书\10下铁指诀.bmp", r"书\10下狮子吼.bmp",
                r"书\10下狂风迅雷功.bmp", r"书\10下真武七截阵.bmp", r"书\10下银索金铃索法.bmp",
            ],
            "10冰蛛开启": False,
            "10机关猿开启": False,
            "10邪教屠神开启": False,
        }
        self.data["武器未解锁孔"] = self.dm.GetDirPath(r"pic\武器镶嵌",filter="未打孔")
        self.data["武器宝石"] = self.dm.GetDirPath(r"pic\武器镶嵌",filter="已打孔_宝石")
        self.data["武器宝玉"] = self.dm.GetDirPath(r"pic\武器镶嵌",filter="已打孔_宝玉")

        self.data["奇遇难度"] = self.publicData["主c"]["奇遇启动难度"]


    def Process(self):
        self.MoveSafe()
        self.log.info("当前阶段 %s" % self.publicData["系统"]["主要阶段"])
        if "" == self.publicData["系统"]["主要阶段"]:
            self.modifyStage(main_stage="创建房间")
            self.log.info("主c创建房间")
        self.log.info("当前阶段 %s" % self.publicData["系统"]["主要阶段"])
        main_stage = self.publicData["系统"]["主要阶段"]
        if self.publicData["boss头像出现次数"] > 6:
            if main_stage=="存档":
                self.publicData["boss头像出现次数"]=0
            self.log.info("出现boss 不进行发育")
            time.sleep(1)
            return 0

        if main_stage == "创建房间":
            is_get = self.dm.SearchPngClick(810, 425, 1245, 655, "dota2\离开比赛.bmp|dota2\离开比赛2.bmp", 0.8, 1,
                                            1, 1, 10, 10)
            if is_get == 1:
                self.log.info("重新启动后 点击上把离开比赛")
            time.sleep(1)

            for i in range(10):
                if i==9:
                    self.publicData["系统"]["主要阶段"]="退出游戏"
                    break
                res=self.CreateRoom()
                if res==1:
                    break
                if res==0:
                    self.dm.SearchPngClick(1040, 670, 1260, 710, "dota2\房主开始比赛.bmp|dota2\房主开始比赛2.bmp",0.8, 1, 0, 1, 0, -20)
            self.log.info("开始等待开始游戏")
            wait_time = self.publicData["基础配置"]["房间等待时间"]

            while wait_time > 0 and self.get_main_stage() == "创建房间":
                wait_time = wait_time - 1
                self.log.info("房间等待 %s" % wait_time)
                # 人满
                is_get = self.dm.SearchPngClick(500, 325, 750, 375, "dota2\接受开始.bmp|dota2\接受开始2.bmp", 0.8,
                                                1, 0.5, 0, 0, 0)

                if is_get == 1:
                    self.publicData["系统数据"]["总局数"] += 1
                    is_get = self.dm.SearchPngClick(500, 325, 750, 375, "dota2\接受开始.bmp|dota2\接受开始2.bmp",
                                                    0.8, 50, 0.5, 1, 100, 15, is_wait=1)
                    self.log.info("接受开始,进入游戏")
                    if is_get == 1:
                        is_get = self.dm.SearchPngClick(500, 325, 750, 375, "dota2\接受开始.bmp|dota2\接受开始2.bmp",
                                                        0.8, 1, 0.5, 1, 100, 15)
                        if is_get==1:
                            wait_time = 0
                        else:
                            self.modifyStage(main_stage="加载游戏")
                    break

                if self.publicData["基础配置"]["房间人数"] == 2:
                    is_get1 = self.dm.SearchPngClick(1027, 136, 1107, 165, "dota2\玩家4_2.bmp",0.8, 1, 0, 0, 0, 0)
                    if is_get1==1:
                        wait_time=0
                    is_get2 = self.dm.SearchPngClick(1182, 679, 1245, 699, "dota2\玩家4_2_1.bmp", 0.8, 1, 0, 0, 0, 0)
                    if is_get2 == 1:
                        wait_time = 0
                        self.dm.LeftClick(1122,708,1)
                elif self.publicData["基础配置"]["房间人数"] == 3:
                    is_get1 = self.dm.SearchPngClick(1027, 136, 1107, 165, "dota2\玩家4_3.bmp",0.8, 1, 0, 0, 0, 0)
                    if is_get1==1:
                        wait_time=0
                    is_get2 = self.dm.SearchPngClick(1182, 679, 1245, 699, "dota2\玩家4_3_1.bmp", 0.8, 1, 0, 0, 0, 0)
                    if is_get2 == 1:
                        wait_time = 0
                        self.dm.LeftClick(1122,708,1)
                elif self.publicData["基础配置"]["房间人数"] == 1:
                    wait_time=0
                is_get = self.dm.SearchPngClick(892, 300, 1107, 600, "dota2\创建自定义房间.bmp", 0.8, 1, 0, 0, 0, 0)
                if is_get==1:
                    is_get=self.dm.WaitPngDisappear(892, 300, 1107, 600, "dota2\创建自定义房间.bmp",0.8, 10, 1, 0, 0, 0)
                    if is_get==1:
                        break

                time.sleep(0.3)
            # 等待到时间
            if self.get_main_stage() == "创建房间":
                self.publicData["系统数据"]["总局数"] += 1
                is_get=self.dm.SearchPngClick(1040, 670, 1260, 710, "dota2\房主开始比赛.bmp|dota2\房主开始比赛2.bmp", 0.8, 0,
                                       0, 0, 0, 0)
                if is_get==0:
                    self.dm.LeftClick(1186,700,1)
                self.dm.SearchPngClick(1040, 670, 1260, 710, "dota2\房主开始比赛.bmp|dota2\房主开始比赛2.bmp", 0.8, 5,
                                       0.5, 1, 50, 5, is_wait=1)
                is_get = self.dm.SearchPngClick(500, 325, 750, 375, "dota2\接受开始.bmp|dota2\接受开始2.bmp", 0.8, 50,
                                                0.5, 1, 100, 15, is_wait=1)
                if is_get == 1:
                    is_get = self.dm.SearchPngClick(500, 325, 750, 375, "dota2\接受开始.bmp|dota2\接受开始2.bmp",
                                                    0.8, 1, 0.5, 1, 100, 15)
                    if is_get == 1:
                        self.modifyStage(main_stage="退出游戏")
                    else:
                        self.modifyStage(main_stage="加载游戏")
        elif main_stage == "加载游戏":
            self.modifyStage(second_stage=1)
            if self.data["开始跑马时间"] < 150.0:
                is_get1 = self.dm.WaitPngDisappear(590, 510, 700, 600, "存档\拼命加载中.bmp", 0.8, 1, 0)
                is_get2 = self.dm.WaitPngDisappear(0, 0, 30, 30, "存档\跑马左上角返回.bmp", 0.8, 1, 0)
                if is_get1 == 1 and is_get2 == 1:
                    self.data["开始跑马时间"] = time.time()
            if time.time() - self.data["开始跑马时间"] > self.publicData["系统"]["跑马超时时间"] and self.data[
                "开始跑马时间"] > 150.0:
                self.log.info("启动跑马重连机制")
                self.dm.LeftClick(16, 16, 1)
                self.data["开始跑马时间"] = 0.0
                # 可能会有多余的断开链接弹窗
                is_get = self.dm.SearchPngClick(450, 250, 900, 500,
                                                "dota2\已断开服务器连接.bmp|dota2\已断开服务器连接1.bmp|dota2\已断开服务器连接2.bmp|dota2\已断开服务器连接3.bmp|dota2\已断开服务器连接4.bmp|dota2\已断开服务器连接5.bmp",
                                                0.8, 1, 0, 1, 120, 90)
                if is_get == 1:
                    time.sleep(1)
                self.dm.SearchPngClick(1010, 625, 1245, 655, "dota2\断开连接.bmp|""dota2\断开连接2.bmp", 0.8, 10, 0,
                                       1, 10, 10, is_wait=1)
                return 0
            is_get = self.dm.SearchPngClick(590, 636, 690, 680, "梦入江湖.bmp", 0.8, 1, 0.5, 0, 0, 0)
            if is_get == 1 :
                self.modifyStage(main_stage="关卡选择")
            is_get2 = self.dm.SearchPngClick(500, 1, 650, 35, "存档\选难度界面倒计时框框.bmp", 0.95, 1, 0.5, 0, 0, 0)
            if is_get2 == 1:
                self.data["开始跑马时间"] = 0.0
        elif main_stage == "关卡选择":
            time.sleep(1)
            self.log.info("主c选择关卡")
            self.ChoseLevel()
            is_get = self.dm.SearchPngClick(1000, 625, 1250, 700, "开始游戏.bmp", 0.8, 10, 0.5, 0, 0, 0)
            if is_get == 1:
                self.modifyStage(main_stage="人物选择")
        elif main_stage == "人物选择":
            self.ChooseSect()
        elif main_stage == "分解":
            self.publicData["系统数据"]["进入游戏数"] += 1
            self.data["本局开始时间"] = time.time()

            is_get = self.dm.SearchPngClick(125, 650, 165, 675, "f4.bmp", 0.8, 1000, 0.1, 0, 0, 0)
            if is_get == 1:
                # 卡会心
                self.StuckBug1()
            self.log.info("开始保存大哥头像")
            dm_ret = self.dm.Capture(42, 50, 49, 57, "dage.bmp")
            self.log.info("保存大哥头像结束 结果 %s" % dm_ret)
            self.SwitchQSkill(self.publicData["通用"]["落地切换q"])
            time.sleep(1)
            # self.AttackWorlf()

            if self.publicData["通用"]["自动释放q"]:
                time.sleep(1)
                self.AutoQ()
            self.modifyStage(main_stage="发育")
            self.cost_time_debug("开始",init=True)
        elif main_stage == "发育":
            if self.publicData["是否打断游戏进程"]:
                self.GetArmsFast()
                is_get = self.dm.SearchPngClick(400, 516, 800, 548, "主线\稍后再选.bmp", 0.8, 3, 0.1, 0, 0, 0)
                time.sleep(0.2)
                if is_get == 1:
                    self.ChooseAdventure()
                    return
            self.JuniorSister()
            self.DaHuanDdan()
            self.EatBook()
            self.GetGem()
            self.DelayingEnemy()
            if self.publicData["是否发育"] is False:
                self.modifyStage(main_stage="等待")
                self.modifyStage(second_stage=99999)
            second_stage = self.get_second_stage()
            self.log.info(second_stage)
            cost_time = time.time() - self.data["本局开始时间"]
            self.log.info("costxxxxxx %s" % cost_time)
            if cost_time  > float(self.publicData["主c"]["奇遇启动时间"]) and second_stage in [22,23]:
                self.log.info("该打奇遇了")
                self.modifyStage(second_stage=99)
            if second_stage == 1:
                # 推少量主线
                self.GoSect()
                for i in range(2):
                    res = self.CompleteMainTask1(7, 20)
                    self.log.info(res)
                    if res==3 or res ==5 :
                        self.UpgradeMarrowCleansingSutra()
                    if res > 7:
                        self.modifyStage(second_stage=second_stage + 1)
                        self.UpgradeMarrowCleansingSutra()
                        break
            elif second_stage == 2:
                res = self.ExchangeMilitaryAchievements(2, isGoHome=False)
                res=self.XiuLian(1)
                if res>1:
                    self.modifyStage(second_stage=second_stage + 1)
            elif second_stage == 3:
                # 刷新w 技能
                self.MoveSafe()
                self.GoSect()
                res = self.ChooseWKill(self.publicData["主c"]["w外功功法"], self.publicData["主c"]["w内功功法"])
                self.UpgradeMarrowCleansingSutra()
                if res == 1:
                    self.modifyStage(second_stage=second_stage + 1)
                    self.UseSkillBook(n=20)
            elif second_stage == 4:
                # 推少量主线
                self.GoSect()
                res = self.CompleteMainTask1(9, 20)
                if res > 9:
                    self.modifyStage(second_stage=second_stage + 1)
                    self.data["最近一次大还丹时间"] = time.time()
                    self.UpgradeMarrowCleansingSutra()
                    self.XiuLian(5)

            elif second_stage == 5:
                self.log.info(self.data["是否在高昌"])
                self.JoinGaoChangCheck(1)

                if self.data["高昌"]["1"] is False:
                    for i in range(3):
                        # 6 右下角2个
                        is_get = self.DotaCheckMoveAttack(21, 643, 600, 547)
                        if is_get == 1:
                            self.data["高昌"]["1"] = True
                            break
                    if self.data["高昌"]["1"] is False:
                        self.data["是否在高昌"] = False
                if self.data["高昌"]["3"] is False:
                    for i in range(3):
                        # 6 7 中间3个
                        is_get = self.DotaCheckMoveAttack(28, 638, 600, 460)
                        if is_get == 1:
                            self.data["高昌"]["3"] = True
                            break
                elif self.data["高昌"]["4"] is False:
                    for i in range(3):
                        # 7 3个
                        is_get = self.DotaCheckMoveAttack(33, 646, 600, 500, step=1)
                        if is_get == 1:
                            self.data["高昌"]["4"] = True
                            gu_bi_num = self.OcrGuBiNum()
                            self.log.info("古币 %s" % gu_bi_num)
                            break
                else:
                    self.modifyStage(second_stage=second_stage + 1)
                    self.XiuLian(7)
            elif second_stage == 6:
                res = self.XiuLian(4)
                if res >= 4:
                    self.modifyStage(second_stage=second_stage + 1)
            elif second_stage == 7:
                # 推武器前所有主线
                res = self.CompleteMainTask1(10, 20)
                if res == 11:
                    self.modifyStage(second_stage=second_stage + 1)
                    self.cost_time_debug("开始解锁洗髓经")
            elif second_stage == 8:
                # 解锁洗髓经
                self.GoSect()
                res = self.UnlockMarrowCleansingSutra()
                if res == 1:
                    self.UnlockOther()
                    self.UpgradeMarrowCleansingSutra()
                    self.modifyStage(second_stage=second_stage + 1)

            elif second_stage == 9:
                self.PleaseEnemy(0)
                res = self.ExchangeMilitaryAchievements(4)
                if res == 1:
                    self.modifyStage(second_stage=second_stage + 1)
                    self.UpgradeMarrowCleansingSutra()
                    self.LearnRSkill(num=1)
            elif second_stage == 10:
                self.GoSect()
                if self.publicData["是否掉线"]:
                    self.UpgradeMarrowCleansingSutra()
                    self.modifyStage(second_stage=second_stage + 1)
                if (self.data["当前心魔次数"]<self.publicData["主c"]["心魔次数"] and self.publicData["基础配置"]["难度"]>=22
                        and self.publicData["基础配置"]["模式"]!="华山之巅") :
                    self.UpgradeMarrowCleansingSutra()
                    res=self.PleaseXinMo(4)
                    if res!=1:
                        self.dm.LeftClick(634,301,1)
                else:
                    self.UpgradeMarrowCleansingSutra()
                    self.modifyStage(second_stage=second_stage + 1)
            elif second_stage == 11:
                # 学习R
                res = self.LearnRSkill(num=20)
                self.data["R技能挑战次数"] += 1
                if res > 3 :
                    self.UseSkillBook(n=20)
                    self.modifyStage(second_stage=second_stage + 1)
                    self.UpgradeMarrowCleansingSutra()
                    # 门派挑战
                    self.SectChallenge()
            elif second_stage == 12:
                # 升级洗髓经
                self.GoSect()
                self.log.info(self.data["洗髓经当前等级"])
                res = self.UpgradeMarrowCleansingSutra()
                if self.data["洗髓经当前等级"] ==3:
                    self.RMarrowCleansingSutra()
                if res == 1:
                    self.modifyStage(second_stage=second_stage + 1)
                    self.cost_time_debug("开始r洗髓经")
            elif second_stage == 13:
                # r洗髓经
                self.GoSect()
                for i in range(5):
                    time.sleep(0.1)
                    res = self.RMarrowCleansingSutra()
                    if res == 1:
                        self.modifyStage(second_stage=second_stage + 1)
                        break
            elif second_stage == 14:
                # 学习R
                res = self.LearnRSkill(num=10)
                self.data["R技能挑战次数"] += 1
                if res > 8 :
                    self.modifyStage(second_stage=second_stage + 1)
            elif second_stage == 15:
                # 融合洗髓经
                res = self.MixMarrowCleansingSutra()
                if res == 1:
                    # self.UnlockArmsAll()  # todo
                    self.modifyStage(second_stage=second_stage + 1)
                    self.cost_time_debug("合成洗髓经")
            elif second_stage == 16:
                # 装备挑战
                res = self.EquipmentChallenge(8)
                if res == 1:
                    self.modifyStage(second_stage=second_stage + 1)
                    self.XiuLian(9)
            # second_stage == 17 与检查守家逻辑 强绑定 需同步修改
            elif second_stage == 17:
                res = self.CompleteMainTask2(12, 20)
                self.log.info(res)
                if res >= 13:
                    # 门派挑战
                    self.SectChallenge()
                    self.modifyStage(second_stage=second_stage + 1)
                    self.EquipmentChallengeAll(9)
                    self.UpgradeArmAuto(target=14)

                    self.cost_time_debug("拿完武器")
            elif second_stage == 18:
                res = self.EquipmentChallengeAll(9)
                if res == 1:
                    self.UpgradeArmAuto(14)
                    self.modifyStage(second_stage=second_stage + 1)
            elif second_stage == 19:
                # 解锁武器
                self.GoSect()
                if self.publicData["基础配置"]["模式"] in ["异国志","侠客行","华山之巅"] :
                    res = self.UnlockArms("NPC选项\大旗密藏.bmp|NPC选项\见蝉知意.bmp|NPC选项\马啸西风.bmp")
                else:
                    res = 1
                if res == 1:
                    self.modifyStage(second_stage=second_stage + 1)
                    self.cost_time_debug("解锁完武器")
            elif second_stage == 20:
                if self.publicData["基础配置"]["难度"] < 14:
                    self.modifyStage(second_stage=second_stage + 1)
                else:
                    res = self.CompleteMainTask3(4, 20)

                    if res > 4:
                        self.modifyStage(second_stage=second_stage + 1)
                        self.XiuLian(11)
            elif second_stage == 21:
                flag = False
                self.GoSect()
                self.log.info("开始升级装备")
                self.dm.KeyPressChar("f1")
                for i in range(10):
                    res = self.UpgradeArmAuto(25)
                    if res == -1:
                        flag=True
                    elif res==2:
                        continue
                    if flag:
                        self.modifyStage(second_stage=second_stage + 1)
                        break
            elif second_stage == 22:
                if self.publicData["主c"]["是否打10"]:
                    # if self.publicData["是否回家过"] or self.publicData["是否回门派过"]:
                    #     if self.OcrGuBiNum()>10000:
                    #         self.XiuLian(13)
                    #     else:
                    #         self.XiuLian(11)
                    sui_yin = self.OcrSuiYinNum()
                    self.log.info(sui_yin)
                    if sui_yin>100000:
                        self.JoinGaoChangCheck(2)
                    else:
                        self.JoinGaoChangCheck(1)
                    if self.data["是否在高昌"]:
                        self.UnlockBoss10()
                        self.DoSupTask10()
                else:
                    self.data["任务"]["10"] = []
                if len(self.data["任务"]["10"]) == 0 :
                    self.log.info(self.data["任务"]["10"])
                    self.PutIntoPublicWarehouse(r"书\10级藏宝图.bmp", n=1)
                    self.modifyStage(second_stage=second_stage + 1)

            elif second_stage == 23:
                self.modifyStage(second_stage=second_stage + 1)
                self.XiuLian(13)
            else:
                self.cost_time_debug("发育完毕")
                self.modifyStage(main_stage="等待")
                self.modifyStage(second_stage=99999)
        elif main_stage == "等待":

            if self.publicData["是否打断游戏进程"]:
                self.GetArmsFast()
                is_get = self.dm.SearchPngClick(400, 516, 800, 548, "主线\稍后再选.bmp", 0.8, 3, 0.1, 0, 0, 0)
                time.sleep(0.2)
                if is_get == 1:
                    self.ChooseAdventure()
                    return
            self.JuniorSister()
            # 主c打奇遇 todo
            self.DaHuanDdan()
            self.GetArmsFast()  # todo 临时规避办法
            self.JuniorSister()
            self.EatBook()
            self.GetGem()
            # 提前攻击帐篷
            res = self.AdvanceAttack()
            if res==1:
                return 0
            now = time.time()
            self.ExchangeMilitaryAchievements(8)
            if now - self.data["本局开始时间"] > float(self.publicData["主c"]["奇遇启动时间"]-100.0) and self.data["奇遇前准备完成"] is False:
                self.PreAdvance()
            if now - self.data["本局开始时间"] > float(self.publicData["主c"]["奇遇启动时间"]):
                self.AdventureAuto()

            self.Challenge_Archive()
        elif main_stage == "存档":
            if self.publicData["是否打断游戏进程"]:
                self.GetArmsFast()
                is_get = self.dm.SearchPngClick(400, 516, 800, 548, "主线\稍后再选.bmp", 0.8, 3, 0.1, 0, 0, 0)
                time.sleep(0.1)
                if is_get == 1:
                    self.ChooseAdventure()
                    return
            self.JuniorSister()
            self.DaHuanDdan()
            second_stage = self.get_second_stage()
            self.log.info(second_stage)
            if second_stage == "存档":
                self.cost_time_debug("开始存档")
                self.publicData["系统数据"]["防守成功数"] += 1
                # 区别第一次进入
                self.modifyStage(second_stage="存档发育")
                self.UseSkillBook(n=20)
                self.SwitchQSkill(self.publicData["通用"]["存档切换q"])
                if self.publicData["通用"]["自动释放q"]:
                    time.sleep(1)
                    self.AutoQ("q")

                res=self.SectChallengeX()
                if res==1:
                    for i in range(10):
                        self.MoveSafe()
                        result = self.ChooseWKill(self.publicData["主c"]["存档w外功功法"], self.publicData["主c"]["存档w内功功法"])
                        if result==1:
                            break
            elif second_stage == "存档发育":
                # 防止宝石暴击 爆仓库
                is_get = self.dm.SearchPngClick(1024, 650, 1122, 680, "存档\宝石\一键合成.bmp|存档\宝石\一键合成2.bmp", 0.9, 3, 0.1, 1,2, 2)

                if self.data["奇遇前准备完成"] is False:
                    self.PreAdvance()
                if self.publicData["基础配置"]["难度"] >= 14 and self.publicData["主c"]["存档后是否推主线"] :
                    for i in range(2):
                        res = self.CompleteMainTask3(10, 20)
                        if res > 10:
                            self.EatBook()
                            # self.GetGem()
                            self.UseTreasureMap(r"书\6级藏宝图.bmp|书\仓库6级藏宝图.bmp")
                            self.UseTreasureMap(r"书\7级藏宝图.bmp|书\仓库7级藏宝图.bmp")
                            self.UseTreasureMap(r"书\8级藏宝图.bmp|书\仓库8级藏宝图.bmp")
                            self.UseTreasureMap(r"书\9级藏宝图.bmp|书\仓库9级藏宝图.bmp")
                            self.UseTreasureMap(r"书\10级藏宝图.bmp|书\仓库10级藏宝图.bmp")
                            self.modifyStage(second_stage="商人购买")
                            break
                else:
                    self.modifyStage(second_stage="商人购买")
                    self.XiuLian(15)
                for i in range(10):
                    is_get = self.dm.SearchPngClick(75, 247, 230, 310,"主线\奇遇空白0.bmp|主线\奇遇空白1.bmp|主线\奇遇空白2.bmp|主线\奇遇空白3.bmp|主线\奇遇空白4.bmp|主线\奇遇空白5.bmp",0.95, 3, 0.1, 0, 0, 0)
                    if is_get == 1:
                        self.AdventureAuto()
                    else:
                        break
                # self.ArmRecastAuto() # 认主后宝石重铸失效
                for i in range(10):
                    res = self.UpgradeArmAuto(20)
                    if res == -1:
                        break
                    elif res == 2:
                        continue

            elif second_stage == "商人购买":
                self.cost_time_debug("开始商人购买")
                self.BuyArchiveMerchant()
                if self.publicData["基础配置"]["模式"]=="异国志":
                    self.modifyStage(second_stage="棋盘")
                else:
                    self.modifyStage(second_stage="金轮")
            elif second_stage == "棋盘":
                # 瞬时完成不卡时间
                res=self.ChallengeBoard(3)
                if self.data["武学境界"] >=2:
                    self.modifyStage(second_stage="打小龙")
                else:
                    self.modifyStage(second_stage="金轮")
            elif second_stage == "打小龙":
                if self.publicData["存档"]["是否打龙"]:

                    res = self.AttackSmallDragon()
                    if res == 1:
                        self.modifyStage(second_stage="金轮")
                else:
                    self.modifyStage(second_stage="金轮")
            elif second_stage == "金轮":
                if self.publicData["存档"]["金轮"] == "不打":
                    self.modifyStage(second_stage="聚贤庄")
                    return 0
                is_get = self.dm.SearchPngClick(1000, 470, 1280, 644, "存档\江湖绝杀令.bmp", 0.8, 5, 0.2, 2, 2, 2)
                if is_get == 1:
                    self.MoveSafe()
                    if self.data["金轮开始时间"] < 150.0:
                        self.log.info("开始打金轮")
                        path = "存档\金轮%s.bmp" % self.publicData["存档"]["金轮"]
                        is_get = self.dm.SearchPngClick(1, 200, 1280, 400, path, 0.8, 20, 0.1, 1, 2, 2)
                        self.GoHome(2)
                        self.DotaBlink(68, 630, 614, 506, n=5)
                        self.data["金轮开始时间"] = time.time()
                elif self.data["金轮开始时间"] > 150.0:
                    self.DotaBlink(68, 630, 614, 506, n=5)
                    now = time.time()
                    if now - self.data["金轮开始时间"] > self.publicData["存档"]["金轮时间"]:
                        self.modifyStage(second_stage="聚贤庄")
                    is_get = self.dm.SearchPngClick(1000, 470, 1280, 644, self.data["轮回金轮"], 0.8, 5, 0.2, 2, 2, 2)
                    if is_get==1:
                        self.modifyStage(second_stage="聚贤庄")
                else:
                    self.modifyStage(second_stage="聚贤庄")
            elif second_stage == "聚贤庄":
                if self.publicData["存档"]["聚贤庄"] != "不打":
                    self.AttackJuXianVillage()
                if self.data["武学境界"] >=2:
                    self.UseAllBossSaveData()
                    self.modifyStage(second_stage="打大龙")
                else:
                    self.modifyStage(second_stage="船坞扶桑")
            elif second_stage == "打大龙":
                if self.publicData["存档"]["是否打龙"]:
                    res=self.AttackDragon()
                    if res==1:
                        self.UseAllBossSaveData()
                        self.UseAllItems()
                        self.UseAllItems()
                        self.UseAllItems()
                        self.UseAllItems()
                        self.modifyStage(second_stage="船坞扶桑")
                    else:
                        self.modifyStage(second_stage="船坞扶桑")
            elif second_stage == "船坞扶桑":
                if self.publicData["基础配置"]["模式"] == "异国志":
                    self.modifyStage(second_stage="进扶桑")
                else:
                    self.modifyStage(second_stage="进船坞")
            elif second_stage == "进船坞":
                self.JoinDockAndFusang()
                if self.publicData["是否进船坞"] == 1:
                    self.modifyStage(second_stage="打船坞")
            elif second_stage == "打船坞":
                res = self.AttackDock()
                time.sleep(1)
                self.UseAllBossSaveData()
                if res == 1:
                    if self.publicData["基础配置"]["模式"] in ["普通", "y", "侠客行", "华山之巅"]:
                        self.UseAllBossSaveData()
                    else:
                        self.UseAllItems()
                    self.modifyStage(second_stage="论剑")
            elif second_stage == "进扶桑":
                self.modifyStage(second_stage="打扶桑")
            elif second_stage == "打扶桑":
                self.modifyStage(second_stage="论剑")

            elif second_stage == "论剑":
                self.log.info("开始论剑检查")
                if self.publicData["存档"]["是否论剑"]:
                   res = self.CompetitionOnHuashan()
                   if res==1:
                       if self.publicData["基础配置"]["模式"] == "华山之巅":
                           self.modifyStage(main_stage="存档等待")
                           self.modifyStage(second_stage="")
                       else:
                           self.modifyStage(second_stage="进黄陵")
                else:
                    if self.publicData["基础配置"]["模式"] == "华山之巅":
                        self.modifyStage(main_stage="存档等待")
                        self.modifyStage(second_stage="")
                    else:
                        self.modifyStage(second_stage="进黄陵")
            elif second_stage == "进黄陵":
                if self.publicData["存档"]["是否刷黄陵"]:
                    for i in range(3):
                        res=self.ImperialMausoleumCarrayEnter()
                        if res == 1:
                            break
                    self.modifyStage(second_stage="打黄陵")
                    self.data["黄陵开始时间"]=time.time()

                else:
                    self.modifyStage(main_stage="存档等待")
                    self.modifyStage(second_stage="")
            elif second_stage == "打黄陵":
                self.log.error("打皇陵")
                res=self.ImperialMausoleuChose()
                if res ==1:
                    self.log.info("黄陵以选择")
                    self.modifyStage(second_stage="进高昌")
                    return 0
                self.log.error("检查是否在黄陵")
                now=time.time()
                if (now-self.data["黄陵开始时间"])>self.publicData["通用"]["黄陵超时时间"]:
                    self.log.info("黄陵超时")
                    self.modifyStage(second_stage="进高昌")
                    return 0
                is_get = self.CheckPersonPosition(93, 649, 0.8, 1, 1, 267, 59, 550, 283)
                if is_get == 1:
                    self.publicData["人物不在黄陵次数"] = 0
                else:
                    self.log.info("人物不在黄陵次数")
                    self.publicData["人物不在黄陵次数"] += 1
                if self.publicData["人物不在黄陵次数"] > 8:
                    self.modifyStage(second_stage="进高昌")
                time.sleep(0.5)
                self.log.error("检查任务是否在黄陵结束")
            elif second_stage == "进高昌":
                self.log.error("打高昌")
                if self.publicData["存档"]["是否打高昌"]:
                    res = self.JoinGaoChangX()
                    if res == 1:
                        self.modifyStage(second_stage="打高昌")
                else:
                    self.modifyStage(main_stage="存档等待")

            elif second_stage == "打高昌":
                self.log.error("打高昌")

                res = self.AttackGaoChangX()
                time.sleep(1)
                self.UseAllBossSaveData()
                if res == 1:
                    self.modifyStage(main_stage="存档等待")


        elif main_stage == "存档等待":

            if self.publicData["基础配置"]["模式"] in ["普通", "y", "侠客行", "华山之巅"]:
                self.UseAllBossSaveData()
                self.UseAllBossSaveData()
            else:
                self.UseAllItems()
                self.UseAllItems()
            if self.publicData["每日"]["排行榜奖励"]:
                self.GetRankingReward()
            self.log.info("开始分解装备 吃静脉奇石")
            self.EquipArms()
            if self.publicData["每日"]["是否轮回狂风快刀"]:
                if self.index % self.publicData["每日"]["轮回狂风间隔"] == 0:
                    self.Reincarnation()
            if self.publicData["每日"]["金锭"]:
                self.CollectGoldIngots()
            self.EatStone()
            self.modifyStage(main_stage="退出游戏")
        elif main_stage == "退出游戏":
            self.log.info("本局游戏结束")
            self.dm.UnBindWindow()
            time.sleep(1)
            return 1
        else:
            self.log_stage()
        time.sleep(0.1)

    def DoMainTask(self,array_list,pic_name,n,step,blink_num=0):
        length=len(array_list)
        for i in range(int(n)):
            if self.publicData["是否回家过"]:
                return
            x=array_list[i%length]
            self.DotaBlink(x[0],x[1],x[2],x[3],blink_num)
            time.sleep(step)
            is_get = self.dm.WaitPngDisappear(1195, 91, 1275, 106, pic_name, 0.9, 1, 0)
            if is_get==0:
                return 0
        return 1

    # todo
    def UnlockArms(self,path):
        self.log.info("开始解锁武器")
        is_get=self.AccessNPC(62, 663,581, 222)

        # path = "存档\大旗秘藏.bmp|存档\见禅知意.bmp|存档\浪迹天涯.bmp" # todo
        if is_get==1:
            is_get = self.dm.WaitPngDisappear(447, 619, 925, 714, path, 0.9, 5, 0.102, 2, 10, 10,is_wait=1)
            if is_get==0:
                return 1
        return 0

    def UnlockArmsAll(self):
        self.log.info("开始解锁武器")
        is_get = self.AccessNPC(62, 663, 581, 222)
        self.BuyAllGoods2()
        # path = "存档\大旗秘藏.bmp|存档\见禅知意.bmp|存档\浪迹天涯.bmp" # todo
        path = "存档\大旗秘藏.bmp|存档\见禅知意.bmp"
        if is_get == 1:
            is_get = self.dm.WaitPngDisappear(447, 619, 925, 714, path, 0.9, 5, 0.102, 2, 10, 10, is_wait=1)
            if is_get == 0:
                return 1
        return 0

    # 修炼层数 n为对应完成
    def XiuLian(self, n):
        if self.data["修炼完毕"]:
            return 16
        is_get = self.dm.SearchPngClick(360, 343, 866, 371, "主线\技能_效果.bmp", 0.9, 1, 0.01, 1, 10, 10)
        if is_get == 1:
            self.dm.SearchPngClick(360, 343, 866, 371, "主线\技能_效果.bmp", 0.9, 1, 0.1, 1, 10, 10)
            return 1
        is_get = self.AccessHomeNPC("修炼")
        if is_get <= 0:
            return -1
        path = "主线\修炼\第1层0.bmp|主线\修炼\第1层1.bmp|主线\修炼\第2层0.bmp|主线\修炼\第2层1.bmp|主线\修炼\第3层0.bmp|主线\修炼\第3层1.bmp|主线\修炼\第4层0.bmp|主线\修炼\第4层1.bmp|主线\修炼\第5层0.bmp|主线\修炼\第5层1.bmp|主线\修炼\第6层0.bmp|主线\修炼\第6层1.bmp|主线\修炼\第7层0.bmp|主线\修炼\第7层1.bmp|主线\修炼\第8层0.bmp|主线\修炼\第8层1.bmp"

        res=self.dm.SearchPngClickEX(475, 651, 919, 704, path, 0.9,20,0.05,0,0,0)
        self.data["当前修炼层数"] = res
        self.log.info("当前修炼层数%s" % res)

        if res>n:
            return res
        if res in[0,1]:
            path1 = r"主线\修炼\第1层0.bmp"
            path2 = r"主线\修炼\第1层1.bmp"

            is_get = self.dm.SearchPngClick(478, 652, 837, 701, path1, 0.9, 1, 0.01, 0, 0, 0)
            if is_get==1:
                time.sleep(0.2)
                self.dm.LeftClick(898,688,1)

            is_get2 = self.dm.SearchPngClick(478, 652, 837, 701, path2, 0.9, 20, 0.1, 2, 5, 5)
            for i in range(3):

                res = self.ExchangeMilitaryAchievements(4, isGoHome=False)

            is_get = self.dm.SearchPngClick(360, 343, 866, 371, "主线\技能_效果.bmp", 0.9, 30, 0.1, 1, 10, 10)
            if is_get2==1:
                self.dm.SearchPngClick(360, 343, 866, 371, "主线\技能_效果.bmp", 0.9, 3, 0.3, 1, 10, 10)
                return res
            if is_get==0:
                return res

            # if is_get2==1:
            #     self.dm.SearchPngClick(281, 200, 971, 540, "主线\修炼\选择技能0.bmp|主线\修炼\选择技能1.bmp", 0.9, 3, 0.3, 2, 10, 10)
            #     return res
            # if is_get==0:
            #     return res
        elif res in[2,3]:
            # path = r"主线\一键修炼.bmp" # todo 容易点击f5
            # self.dm.SearchPngClick(478, 652, 837, 701, path, 0.9, 1, 0.05, 2, 10, 10)
            path1 = r"主线\修炼\第2层0.bmp"
            path2 = r"主线\修炼\第2层1.bmp"
            is_get = self.dm.SearchPngClick(478, 652, 837, 701, path1, 0.9, 1, 0.01, 0, 0, 0)
            if is_get == 1:
                self.dm.LeftClick(898, 688, 1)
            self.dm.SearchPngClick(478, 652, 837, 701, path2, 0.9, 20, 0.05, 2, 10, 10, is_wait=1)
        elif res in[4,5]:
            path1 = r"主线\修炼\第3层0.bmp"
            path2 = r"主线\修炼\第3层1.bmp"
            is_get = self.dm.SearchPngClick(478, 652, 837, 701, path1, 0.9, 1, 0.01, 0, 0, 0)
            if is_get == 1:
                self.dm.LeftClick(898, 688, 1)
            self.dm.SearchPngClick(478, 652, 837, 701, path2, 0.9, 12, 0.05, 2, 10, 10, is_wait=1)
        elif res in [6, 7]:
            path1 = r"主线\修炼\第4层0.bmp"
            path2 = r"主线\修炼\第4层1.bmp"
            is_get = self.dm.SearchPngClick(478, 652, 837, 701, path1, 0.9, 1, 0.01, 0, 0, 0)
            if is_get == 1:
                self.dm.LeftClick(898, 688, 1)
            self.dm.SearchPngClick(478, 652, 837, 701, path2, 0.9, 12, 0.05, 2, 10, 10, is_wait=1)
        elif res in [8, 9]:
            path1 = r"主线\修炼\第5层0.bmp"
            path2 = r"主线\修炼\第5层1.bmp"
            is_get = self.dm.SearchPngClick(478, 652, 837, 701, path1, 0.9, 1, 0.01, 0, 0, 0)
            if is_get == 1:
                self.dm.LeftClick(898, 688, 1)
            self.dm.SearchPngClick(478, 652, 837, 701, path2, 0.9, 12, 0.05, 2, 10, 10, is_wait=1)
        elif res in [10, 11]:
            path1 = r"主线\修炼\第6层0.bmp"
            path2 = r"主线\修炼\第6层1.bmp"
            is_get = self.dm.SearchPngClick(478, 652, 837, 701, path1, 0.9, 1, 0.01, 0, 0, 0)
            if is_get == 1:
                self.dm.LeftClick(898, 688, 1)
            self.dm.SearchPngClick(478, 652, 837, 701, path2, 0.9, 12, 0.05, 2, 10, 10, is_wait=1)
        elif res in [12, 13]:
            path1 = r"主线\修炼\第7层0.bmp"
            path2 = r"主线\修炼\第7层1.bmp"
            is_get = self.dm.SearchPngClick(478, 652, 837, 701, path1, 0.9, 1, 0.01, 0, 0, 0)
            if is_get == 1:
                self.dm.LeftClick(898, 688, 1)
            self.dm.SearchPngClick(478, 652, 837, 701, path2, 0.9, 12, 0.05, 2, 10, 10, is_wait=1)
        elif res in [14, 15]:
            path1 = r"主线\修炼\第8层0.bmp"
            path2 = r"主线\修炼\第8层1.bmp"
            is_get = self.dm.SearchPngClick(478, 652, 837, 701, path1, 0.9, 1, 0.01, 0, 0, 0)
            if is_get == 1:
                self.dm.LeftClick(898, 688, 1)
            self.dm.SearchPngClick(478, 652, 837, 701, path2, 0.9, 12, 0.05, 2, 10, 10, is_wait=1)
            self.data["修炼完毕"] = True
        else:
            # 怕误点武器
            path = r"主线\修炼\一键修炼.bmp"
            self.dm.SearchPngClick(478, 652, 837, 701, path, 0.9, 20, 0.01, 2, 5, 25, is_wait=1)
        return res

    # 选择w技能
    def ChooseWKill(self,name1,name2):
        self.log.info("刷w功法")
        self.GoSect()
        path =r"功法\%s.bmp|功法\%s.bmp"%(name1,name2)
        is_get = self.dm.SearchPngClick(456, 629, 495, 666, path, 0.8, 3, 0.1, 0, 0, 0)
        if is_get == 1:
            time.sleep(1)
            is_get = self.dm.SearchPngClick(456, 629, 495, 666, path, 0.8, 1, 0.1, 0, 0, 0)
            if is_get == 1:
                return 1

        for i in range(10):
            if i % 3 == 0:
                self.MoveSafe()
            self.dm.LeftClick(485, 634, 1)
            is_get = self.dm.SearchPngClick(722, 623, 837, 705, "存档\空装备栏.bmp", 0.8, 1, 0, 0, 0, 0)
            if is_get == 0:
                self.GoSect()
            time.sleep(0.3)
            is_get = self.dm.SearchPngClick(456, 629, 495, 666, path, 0.8, 2, 0.1, 0, 0, 0)
            if is_get==1:
                break
        time.sleep(1)
        is_get = self.dm.SearchPngClick(456, 629, 495, 666, path, 0.8, 1, 0.1, 0, 0, 0)
        if is_get == 1:
            return 1
        return 0
    # 门派挑战
    def SectChallenge(self):
        self.log.info("开始门派挑战")
        is_get=self.AccessHomeNPC("挑战")
        if is_get<=0:
            return 0

        is_get = self.dm.SearchPngClick(470, 620, 918, 703, "主线\门派挑战1.bmp|主线\门派挑战2.bmp", 0.8, 10, 0.5, 1, 5, 5)
        if is_get==1:
            is_get = self.dm.SearchPngClick(547, 500, 703, 560, "主线\留待机缘.bmp|主线\留待机缘1.bmp", 0.8, 60, 0.5, 0, 0, 0 )
            if is_get==1:
                is_get = self.dm.SearchPngClick(200, 150, 1200, 250, self.publicData["门派挑战选择配置"], 0.8, 1, 0.5, 1, 20, 20)
                if is_get !=1:
                    self.dm.SearchPngClick(547, 500, 703, 560, "主线\留待机缘.bmp|主线\留待机缘1.bmp", 0.8, 1,  0, 1, 10, 5)
            else:
                return 0
        else:
            return 0

    # 门派挑战
    def SectChallengeX(self):
        self.log.info("开始门派挑战all")
        is_get = self.AccessHomeNPC("挑战")
        if is_get <= 0:
            return 0
        is_get = self.dm.SearchPngClick(470, 620, 918, 703, "主线\门派挑战1.bmp|主线\门派挑战2.bmp", 0.8, 10, 0.5, 1, 5, 5)
        if is_get==1:
            is_get = self.dm.SearchPngClick(547, 500, 703, 560, "主线\留待机缘.bmp|主线\留待机缘1.bmp", 0.8, 60, 0.5, 0, 0, 0 )
            if is_get==1:
                is_get = self.dm.SearchPngClick(200, 150, 1200, 250, self.publicData["门派挑战选择配置"], 0.8, 1, 0.5, 1, 20, 20)
                if is_get !=1:
                    self.dm.SearchPngClick(547, 500, 703, 560, "主线\留待机缘.bmp|主线\留待机缘1.bmp", 0.8, 1,  0, 1, 10, 5)

        is_get = self.dm.SearchPngClick(470, 620, 918, 703, "主线\门派挑战1.bmp|主线\门派挑战2.bmp", 0.8, 1, 0.5, 1, 5, 5)
        if is_get == 1:
            is_get = self.dm.SearchPngClick(547, 500, 703, 560, "主线\留待机缘.bmp|主线\留待机缘1.bmp", 0.8, 60, 0.5, 0,
                                            0, 0)
            if is_get == 1:
                is_get = self.dm.SearchPngClick(200, 150, 1200, 250, self.publicData["门派挑战选择配置"], 0.8, 1, 0.5,
                                                1, 20, 20)
                if is_get != 1:
                    self.dm.SearchPngClick(547, 500, 703, 560, "主线\留待机缘.bmp|主线\留待机缘1.bmp", 0.8, 1, 0, 1, 10,
                                           5)


        is_get = self.dm.SearchPngClick(470, 620, 918, 703, "主线\门派挑战3.bmp|主线\门派挑战3x.bmp", 0.8, 10, 0.5, 1, 5, 5)
        if is_get == 1:
            is_get = self.dm.SearchPngClick(470, 620, 918, 703, "主线\门派挑战3x.bmp", 0.8, 20, 0.5, 1, 5, 5)
            if is_get == 1:
                return 1
            else:
                return 0
        else:
            return 0

    def LearnRSkill(self,num=1):
        if self.data["是否修练完"]:
            return 999
        is_get=self.AccessHomeNPC("心法")
        time.sleep(0.2)
        n = 0
        if is_get > 0:
            path = r"主线\%s.bmp" % self.publicData["主c"]["心法"]
            path = self.dm.GetPicAbsPath(path)
            res, x, y = self.dm.FindPicEx(478, 652, 837, 701, path, "000000", 0.95)
            if res !=-1:
                n=int((x-480)/44)
            is_get = self.dm.SearchPngClick(478, 652, 837, 701, path, 0.9, 3, 0.1, 2, 10, 10)
            if is_get == 0:
                self.data["是否修练完"] = True
                return 9
            for i in range(num):
                time.sleep(0.4)

                res, x, y = self.dm.FindPicEx(478, 652, 837, 701, path, "000000", 0.95)
                if res != -1:
                    now = (x - 480) / 44
                    if now >n:
                        if self.OcrSuiYinNum() < 20000:
                            return now
                        is_get = self.dm.SearchPngClick(478, 652, 837, 701, path, 0.9, 3, 0, 2, 10, 10)
                        n=now
                        if is_get == 0:
                            self.data["是否修练完"] = True
                            return 9
                else:
                    return 9
        return n

    def EquipmentChallenge(self,num=20):
        is_get=self.AccessHomeNPC("装备挑战")
        if is_get>0:
            path = "主线\装备挑战1.bmp|主线\装备挑战2.bmp|主线\装备挑战3.bmp|主线\装备挑战4.bmp|主线\装备挑战5.bmp|主线\装备挑战6.bmp|主线\装备挑战7.bmp|主线\装备挑战8.bmp"
            path=self.dm.GetPicAbsPath(path)
            n=0
            res, x, y = self.dm.FindPicEx(478, 652, 837, 701, path, "000000", 0.95)
            if res != -1:
                n = int((x - 480) / 44)
            is_get = self.dm.SearchPngClick(478, 652, 837, 701, path, 0.9, 1, 0.112, 2, 10, 10)
            if is_get == 0:
                return 1
            for i in range(num):
                time.sleep(0.4)
                res, x, y = self.dm.FindPicEx(478, 652, 837, 701, path, "000000", 0.95)
                if res != -1:
                    now = (x - 480) / 44
                    if now > n:
                        if self.OcrSuiYinNum() < 20000:
                            return 0
                        is_get = self.dm.SearchPngClick(478, 652, 837, 701, path, 0.9, 3, 0, 2, 10, 10)
                        n = now
                        if is_get == 0:
                            self.data["是否修练完"] = True
                            return 1
                else:
                    return 1
            return 0

    def MoveFe(self):
        res, x, y = self.dm.FindPicExS(992, 460, 1280, 650, self.dm.GetPicAbsPath("主线\铁绑定.bmp"), "000000", 0.95)
        if res != - 1:
            self.log.info(res)
            self.dm.DragFast(x + 5, y + 5, 1023, 497)
            return True
        return False
    def EquipmentChallengeAll(self,num=0):
        is_get=self.AccessHomeNPC("装备挑战")
        have_fe = False
        flag = True
        if is_get<=0:
            return 0

        for i in range(num):
            tmp_path="fe.bmp"
            self.log.info("挑战铁%s" % i)
            if have_fe is False:
                have_fe = self.MoveFe()
            if have_fe and flag:
                dm_ret = self.dm.Capture(1011, 483, 1033, 506,tmp_path )
                self.log.info("保存铁像结束 结果 %s" % dm_ret)
                flag = False
            path = "主线\装备挑战1.bmp|主线\装备挑战2.bmp|主线\装备挑战3.bmp|主线\装备挑战4.bmp|主线\装备挑战5.bmp|主线\装备挑战6.bmp|主线\装备挑战7.bmp|主线\装备挑战8.bmp|主线\装备挑战9.bmp"
            is_get = self.dm.SearchPngClick(478, 652, 900, 701, path, 0.9, 1, 0.112, 2, 10, 10)
            is_get = self.dm.SearchPngClick(555, 475, 731, 530,  "主线\挑战次数不足.bmp", 0.8, 10, 0.3, 0, 0, 0)
            if is_get == 1:
                return 1
            for i in range(20):
                time.sleep(0.1)
                self.log.info(i)
                if have_fe is False:

                    res, x, y = self.dm.FindPicExS(992, 460, 1280, 650, self.dm.GetPicAbsPath("主线\铁绑定.bmp"), "000000", 0.95)
                    self.log.info(res)
                    if res != - 1:
                        self.log.info("有铁了")
                        break
                else:
                    is_get = self.dm.WaitPngDisappear(1006, 477, 1038, 510,tmp_path,0.9, 1, 0.02)
                    if is_get==0:
                        dm_ret = self.dm.Capture(1011, 483, 1033, 506, tmp_path)
                        self.log.info("保存铁像结束 结果 %s" % dm_ret)
                        break

        return 1

    def AttackWorlf(self):
        self.dm.SearchPngClick(1135, 100, 1280, 326, "主线\立即前往.bmp", 0.9, 1, 0.03, 1, 20, 5)
        time.sleep(1)
        self.DotaAttack(78, 642, 583, 263)

    # 第2段主线任务
    def CompleteMainTask2(self, n, t):
        now=time.time()
        if now-self.data["本局开始时间"]<float(self.publicData["主c"]["第二阶段主线启动时间"]):
            return 0
        self.GetArmsFast() # todo 临时规避办法
        self.dm.KeyPressChar("f1",num=2)
        step=1
        path = r"主线\07_1大闹敌宴.bmp|主线\08_1合力进击.bmp|主线\09选择.bmp|主线\09_1绑走王子.bmp|主线\10_1扫除埋伏.bmp|主线\11_1背水一战.bmp|主线\12_1力斩敌酋.bmp|主线\13_1反击之时.bmp|主线\14_1肃清叛徒.bmp|主线\15_1击敌困顿.bmp|主线\16_1打蛇七寸.bmp|主线\17_1患难真情.bmp|主线\18_1放火烧仓.bmp|主线\19_1潜龙破阵.bmp"
        path = self.dm.GetPicAbsPath(path)
        x, y, res = self.dm.FindPic(1195,91,1275,106, path, "000000", 0.95, 0)
        if x > 0 and y > 0:
            if res >n:
                return  res
            n = res
        self.dm.SearchPngClick(1135, 100, 1280, 326, "主线\立即前往.bmp", 0.9, 1, 0.03, 1, 20, 5)
        self.publicData["是否回家过"] = False
        time.sleep(0.5)
        if n == 0:
            self.DotaBlink(0, 0, 600, 51)
            is_get = self.dm.WaitPngDisappear(1195,91,1275,106,r"主线\07_1大闹敌宴.bmp",0.9,t,step )
            if is_get==0:
                self.GetArms(n=0)
        elif n == 1:
            time.sleep(0.5)
            self.DotaBlink(28, 622,568, 540,2)
            self.UpgradeArmAuto(14)
            self.UpgradeArmAuto(14)
            is_get = self.dm.WaitPngDisappear(1195,91,1275,106,r"主线\08_1合力进击.bmp",0.9,t,step)
        elif n == 2:
            is_get = self.dm.WaitPngDisappear(1195,91,1275,106, r"主线\09选择.bmp", 0.9, 1, 0.3, 1, 37, 82)
        elif n == 3:
            self.DotaBlink(0, 0,700, 51)
            is_get = self.dm.WaitPngDisappear(1195,91,1275,106,r"主线\09_1绑走王子.bmp", 0.9, t, step)
            if is_get == 0:
                self.GetArms(n=1)
        elif n == 4:
            time.sleep(1)
            tmp=[[0, 0, 259, 58],[0, 0, 237, 400],[0, 0, 50, 336]]
            self.DotaBlink(0, 0, 259, 158)
            self.DoMainTask( tmp,r"主线\10_1扫除埋伏.bmp",t/2,step*2,0)
        elif n == 5:
            self.DotaAttack(0, 0,893, 51)
            is_get = self.dm.WaitPngDisappear(1195, 91, 1275, 106, r"主线\11_1背水一战.bmp", 0.9, t/2 , step)
            if is_get == 1:
                self.dm.KeyPressChar("f1",2)
                self.DotaBlink(0, 0, 950, 51)
            is_get = self.dm.WaitPngDisappear(1195, 91, 1275, 106, r"主线\11_1背水一战.bmp", 0.9, t/2 , step)
        elif n == 6:
            time.sleep(0.5)
            self.DotaBlink(0, 0, 484, 51,2)
            is_get = self.dm.WaitPngDisappear(1195,91,1275,106,r"主线\12_1力斩敌酋.bmp", 0.9, t, step )
            if is_get == 0:
                self.GetArms(n=2)
        elif n == 7:
            self.DotaBlink(109, 604, 525, 375)
            for i in range(t*2):
                is_get = self.dm.WaitPngDisappear(1195, 91, 1275, 106, r"主线\13_1反击之时.bmp", 0.9, 1, 0.5)
                if is_get==1:
                    self.DotaAttack(109, 604, 525, 375)
                else:
                    break
        elif n == 8:
            is_get = self.dm.WaitPngDisappear(1195, 91, 1275, 106, r"主线\14_1肃清叛徒.bmp", 0.9, t , 0.5*step)
            if is_get==0:
                self.GetArms(n=3)
            else:
                self.DotaAttack(0, 0, 807, 51)
                is_get = self.dm.WaitPngDisappear(1195, 91, 1275, 106, r"主线\14_1肃清叛徒.bmp", 0.9, t, 0.5*step)
                if is_get == 0:
                    self.GetArms(n=3)
        elif n == 9:
            self.UpgradeArmAuto(14)
            self.DotaBlink(0, 0, 812, 30,2)
            tmp = [[0, 0, 485, 51], [0, 0, 812, 30]]
            self.DoMainTask(tmp, r"主线\15_1击敌困顿.bmp",n,step)
        elif n == 10:
            time.sleep(0.519)

            self.DotaBlink(0, 0, 823, 51, 2)
            tmp = [[0, 0, 623, 51], [0, 0, 823, 51]]
            is_get=self.DoMainTask(tmp, r"主线\16_1打蛇七寸.bmp", n, step)

            if is_get==0:
                self.GetArms(n=4)
        elif n==11:
            time.sleep(0.5)
            self.UpgradeArmAuto(14)
            self.DotaBlink(0, 0, 1199, 283,2)
            tmp = [[0, 0, 861, 48], [0, 0, 1199, 283]]
            is_get = self.DoMainTask(tmp, r"主线\17_1患难真情.bmp", n, step)
        elif n == 12:
            for i in range(4):
                if self.publicData["是否回家过"] or self.publicData["是否回门派过"]:
                    self.publicData["是否回家过"] = False
                    self.publicData["是否回门派过"] = False
                    return 11

                self.dm.KeyPressChar("f1")
                self.dm.KeyPressChar("f1")
                self.DotaAttack(14, 599, 512, 308)
                time.sleep(1)
                is_get = self.dm.SearchPngClick(1000, 470, 1280, 644, "主线\燃油.bmp", 0.8, 1, 0, 0, 0, 0)
                if is_get==0:
                    self.PickUp(14, 599, 800, 420)
                    self.PickUp(0, 0, 699, 389)
                is_get = self.dm.SearchPngClick(1000, 470, 1280, 644, "主线\燃油.bmp", 0.8, 5, 0.5, 2, 2, 2)
                if is_get==1:
                    time.sleep(1)
                    is_get = self.dm.WaitPngDisappear(1195, 91, 1275, 106, r"主线\18_1放火烧仓.bmp", 0.9, 3, 0.5)
                    if is_get==0:
                        self.GetArms(n=5)
                        break
        elif n == 13:
            self.GoSect()
            return 13
        else:
            return -1
        if n % 2 ==0:
            self.dm.SearchPngClick(996, 460, 1279, 646, "主线\高级经验丹.bmp", 0.9, 1, 0, 4, 5, 5)
        return n

    # 第3段主线任务
    def CompleteMainTask3(self, n, t):
        self.dm.KeyPressChar("f1",num=2)
        # t=t*5
        # step=0.2
        step=1
        path = r"主线\19_1潜龙破阵.bmp|主线\20_1佯攻大营.bmp|主线\21_1除恶务尽.bmp|主线\22_1风波再起.bmp|主线\23_1再探敌营.bmp|主线\24_1截取密报.bmp|主线\25_1世家野心.bmp|主线\26_1达摩遗蜕.bmp|主线\27_1雁门关外.bmp|主线\28_1丐帮大会.bmp|主线\29_1山中老人.bmp|主线\30_1疑云密布.bmp"
        path = self.dm.GetPicAbsPath(path)
        x, y, res = self.dm.FindPic(1195,91,1275,106, path, "000000", 0.95, 0)
        if x > 0 and y > 0:
            if res>n:
                return res
            n = res
        self.log.info(n)
        if n==-1:
            return n
        is_get = self.dm.SearchPngClick(1135, 100, 1280, 326, "主线\立即前往.bmp", 0.9, 1, 0.03, 1, 20, 5)
        self.publicData["是否回家过"] = False


        if n==5:
            time.sleep(0.3)
        else:
            time.sleep(0.5)
        if n == 0:
            tmp=[[0, 0, 500, 576],[98, 613, 500, 576],[0, 0, 640, 100]]
            self.DoMainTask(tmp,r"主线\19_1潜龙破阵.bmp",t,step*2,0)

        elif n == 1:

            tmp = [[0, 0, 400, 250], [0, 0, 800, 250], [0, 0, 500, 576], [0, 0, 640, 100]]
            self.dm.SearchPngClick(996, 460, 1279, 646, "主线\高级经验丹.bmp", 0.9, 1, 0, 6, 5, 5, is_wait=1)
            self.UseSkillBook(n=20)
            for i in range(10):
                res = self.UpgradeArmAuto(14)
                if res == -1:
                    break
            for i in range(3):
                res=self.ArmRecastAuto()
                if res == -1:
                    break
            self.DoMainTask(tmp, r"主线\20_1佯攻大营.bmp", t, step, 0)

        elif n == 2:
            self.DotaBlink(0,0,1200,360,n=2)
            is_get = self.dm.WaitPngDisappear(1195,91,1275,106, r"主线\21_1除恶务尽.bmp", 0.9, t, step)

        elif n == 3:
            self.DotaBlink(0,0,60,360,n=2)
            is_get = self.dm.WaitPngDisappear(1195,91,1275,106,r"主线\22_1风波再起.bmp", 0.9, t, step)

        elif n == 4:
            time.sleep(0.8)
            self.DotaMove(0, 0, 764, 270)
            time.sleep(1)
            self.dm.LeftClick(796, 299, 1)
            time.sleep(0.5)
            self.dm.LeftClick(499, 682, 1)
            self.DotaBlink(63, 610, 640, 414, n=2)
            time.sleep(0.5)
            self.DotaBlink(63, 610, 630, 410, n=3)
            for i in range(5):
                is_get = self.dm.SearchPngClick(300, 400, 800, 680, "主线\蛮军前营.bmp", 0.9, 1, 0.03, 1, 5, 5)
                time.sleep(0.2)
                start_time = time.time()
                self.UpgradeArmAuto(25)
                end_time = time.time()
                sleep_time=3.8-(end_time-start_time)
                if sleep_time<=0.0:
                    sleep_time=0.0
                time.sleep(sleep_time)
                self.PutIntoPublicWarehouse(r"书\8级藏宝图.bmp")
                is_get = self.dm.WaitPngDisappear(1195, 91, 1275, 106, r"主线\23_1再探敌营.bmp", 0.9, 1, step)
                if is_get==0:
                    break
        elif n == 5:
            # 此处特殊加速不阻塞
            self.log.info("截取密报")
            is_get = self.dm.SearchPngClick(666,675,724,695, "主线\体力.bmp", 0.9, 1, 0.0, 0, 0, 0)
            if is_get==0:
                return n
            for i in range(6):
                self.dm.dm.MoveTo(43, 596)
                time.sleep(0.08)
                self.dm.dm.LeftClick()
                self.log.info("截取密报1")
                is_get = self.CheckPersonPositionSuper(0, 0, 0.9, 1, 0, 400, 230, 850, 650)
                self.log.info("截取密报2")
                if is_get==0:
                    self.log.info("截取密报3")
                    break
            self.log.info("截取密报4")
            is_get = self.CheckPersonPositionSuper(0, 0, 0.9, 1, 0, 400, 230, 850, 650)
            if is_get==1:
                self.log.info("截取密报5")
                self.dm.dm.KeyPressChar("f4")
            else:
                self.log.info("截取密报6")
                self.DotaBlinkSuper(340, 240,n=6)
                time.sleep(0.3)
                self.dm.dm.KeyPressChar("f4")
            self.log.info("截取密报7")
        elif n == 6:
            time.sleep(0.5)
            self.DotaBlink(37, 620, 486, 210,3)
            for i in range(n):
                self.DotaAttack(0, 0, 435, 532)
                is_get = self.dm.WaitPngDisappear(1195,91,1275,106,r"主线\25_1世家野心.bmp", 0.9, 1, step )
                if is_get == 0:
                    break
                time.sleep(1)
                self.dm.SearchPngClick(996, 460, 1279, 646, "主线\高级经验丹.bmp", 0.9, 1, 0, 2, 5, 5, is_wait=1)
                self.DotaAttack(0, 0, 486, 210)
                time.sleep(1)

        elif n == 7:
            time.sleep(0.5)
            for i in range(2*n):
                self.DotaBlink(0, 0, 589, 118)
                is_get = self.dm.WaitPngDisappear(1195, 91, 1275, 106, r"主线\26_1达摩遗蜕.bmp", 0.9, 1, 0.5)
                if is_get == 0:
                    break
                self.DotaBlink(0, 0, 589, 555)
        elif n == 8:
            self.DotaBlink(0, 0, 800, 300)
            is_get = self.dm.WaitPngDisappear(1195, 91, 1275, 106, r"主线\27_1雁门关外.bmp", 0.9, t , 0.5*step)
            if is_get!=0:
                self.DotaBlink(0, 0, 800, 555)
                is_get = self.dm.WaitPngDisappear(1195, 91, 1275, 106, r"主线\27_1雁门关外.bmp", 0.9, t, 0.5*step)
        elif n == 9:
            time.sleep(1)
            self.DotaBlink(0, 0, 800, 300)
            is_get = self.dm.WaitPngDisappear(1195, 91, 1275, 106, r"主线\28_1丐帮大会.bmp", 0.9, t/2, 0.5*step)
            if is_get == 1:
                self.DotaBlink(0, 0, 700, 300)
                is_get = self.dm.WaitPngDisappear(1195, 91, 1275, 106, r"主线\28_1丐帮大会.bmp", 0.9, t/2, 0.5*step)
            if is_get == 1:
                self.DotaAttack(0, 0, 812, 300)
                is_get = self.dm.WaitPngDisappear(1195, 91, 1275, 106, r"主线\28_1丐帮大会.bmp", 0.9, t/2, 0.5*step)
            if is_get == 1:
                self.DotaAttack(0, 0, 700, 251)
                is_get = self.dm.WaitPngDisappear(1195, 91, 1275, 106, r"主线\28_1丐帮大会.bmp", 0.9, t/2, 0.5*step)

        elif n == 10:
            time.sleep(0.519)
            self.DotaBlink(0, 0, 619, 122)
            is_get = self.dm.WaitPngDisappear(1195, 91, 1275, 106, r"主线\29_1山中老人.bmp", 0.9, t, 0.5*step)
        elif n==11:
            self.GoSect()
            return 11
        else:
            return 12
        is_get = self.dm.SearchPngClick(996, 460, 1279, 646, "主线\高级经验丹.bmp", 0.9, 1, 0, 6, 5, 5)
        return n

    def UseTreasureMap(self, path):
        self.log.info("开始使用%s"%path)
        for i in range(3):
            res=self.GetPublicWarehouse(path)
            if res == 0:
                break
            is_get = self.dm.SearchPngClick(996, 460, 1279, 646, path, 0.9, 5, 0.1, 2, 5, 5)
            if is_get==1:
                time.sleep(0.2)
                self.ChooseAdventure()
            else:
                break

    def CheckTower(self):
        for i in range(10):
            self.dm.LeftClick(68, 638)
            time.sleep(0.5)
            self.dm.LeftClick(597, 251)

            res = self.dm.SearchPngClick(385, 64, 470, 152, r"主线\蛮军箭塔.bmp|主线\蛮军箭塔1.bmp", 0.8, 1, 0, 0, 0, 0)
            if res ==1:
                self.data["防御塔存在"]=True
                return True
        return False

    def AdvanceAttack(self):
        now = time.time()
        self.log.info(self.data["帐篷是否存在"])
        if now - self.data["本局开始时间"] < float(self.publicData["主c"]["速推时间"]) :
            return 0
        if self.data["帐篷是否存在"] is False:
            return 1
        self.log.info("检查提前进攻")
        res = self.dm.SearchPngClick(440, 110, 823, 150, r"主线\大军来袭.bmp", 0.8, 30, 0.5, 0, 0, 0)
        if res == 1:
            self.log.info("提前进攻")
            self.GoHome(no_wait=1, num=3, step=0)  # todo 此处是否要多次

            for i in range(10):
                # 检查是否在家
                is_in = self.CheckPersonPosition(68, 660, 0.8, 1, 1, 100, 100, 980, 620)
                if is_in == 1:
                    break
                else:
                    self.GoHome( no_wait=1, step=0.1)
                    time.sleep(0.1)
            time.sleep(0.5)
        else:
            return 0
        self.log.info("回到家")

        path1 = self.dm.GetPicAbsPath(r"主线\血条友方.bmp")
        path2 = self.dm.GetPicAbsPath(r"主线\血条敌方.bmp|主线\血条敌方2.bmp")
        for i in range(60):
            self.log.info(i)
            self.DaHuanDdan()
            is_get = self.dm.SearchPngClick(200, 1, 1279, 621, r"主线\风二中.bmp|主线\猎户.bmp|主线\何惕守.bmp|主线\萧山.bmp", 0.9, 1, 0.1, 0, 0, 0)
            if is_get==1:
                self.GoHome()
            is_get = self.dm.SearchPngClick(996, 460, 1279, 646, r"主线\勤王诏.bmp", 0.9, 3, 0.1, 2, 5, 5)
            if is_get == 1:
                self.data["帐篷是否存在"] = False
                self.dm.SearchPngClick(996, 460, 1279, 646, r"主线\勤王诏.bmp", 0.9, 3, 0.1, 2, 5, 5)
                if self.publicData["开始打金轮时间"] < 150:
                    self.publicData["开始打金轮时间"] = time.time()
                return 1
            if self.data["帐篷是否存在"] is False or self.publicData["系统"]["主要阶段"] == "存档":
                return 1
            self.log.info("向帐篷移动")
            res2, x2, y2 = self.dm.FindPicEx(100, 0, 1180, 700, path2, "000000", 0.95)
            if x2 > 0:
                if y2<10:
                    y2=10
                self.DotaAttack(0, 0, x2, y2)
                for i in range(30):
                    res2, x2, y2 = self.dm.FindPicEx(100, 0, 1180, 700, path2, "000000", 0.95)
                    if res2 == -1:
                        break
            else:
                self.PickUp(0, 0, 640, 360)
                self.dm.KeyPressChar("f1", num=3,step=0.1)
                time.sleep(0.1)
                self.dm.MoveTo(640, 0)
                time.sleep(0.1)
                self.dm.MoveTo(640, 10)
                self.DotaAttack(0,0,640,60)
                # self.dm.KeyPressChar("a")

        return 0
    # 小师妹
    def JuniorSister(self):
        # 没有解救小师妹
        if self.data["最近一次小师妹时间"] < 150.0 :
            return 0
        now = time.time()
        if now - self.data["最近一次小师妹时间"] < float(self.publicData["主c"]["小师妹间隔"]):
            return 0
        if self.publicData["系统"]["主要阶段"] =="存档":
            self.data["最近一次小师妹时间"] = time.time()+99999.0
            return 0
        # is_get = 0
        if self.data["是否在高昌"]:
            is_get = self.AccessCarryNPC("小师妹")
        else:
            is_get = self.AccessHomeNPC("小师妹")
        if is_get == 1:
            self.dm.LeftClick(498,678,5)
            self.data["最近一次小师妹时间"]=time.time()
            return 1
        else:
            self.dm.SearchPngClick(958, 461, 1275, 651, r"主线\香囊.bmp", 0.9, 1, 0, 2, 1, 1)
        return 0

    def AdventureAuto(self):
        if self.data["奇遇难度"] ==7:
            self.Adventure(6)
        elif self.data["奇遇难度"] > self.publicData["主c"]["奇遇上限难度"]:
            self.data["奇遇难度"] = self.publicData["主c"]["奇遇上限难度"]
            self.Adventure(self.publicData["主c"]["奇遇上限难度"])
        elif self.data["奇遇难度"] > 12:
            self.data["奇遇难度"] = 12
            self.Adventure(self.data["奇遇难度"])
        else:
            self.Adventure(self.data["奇遇难度"])

    # 奇遇
    def Adventure(self, n):
        now=time.time()
        if now-self.data["本局开始时间"]<float(self.publicData["主c"]["奇遇启动时间"]):
            return 0
        if self.publicData["主c"]["奇遇前是否先断脉"]:
            if self.data["当前战功兑换层数"]<9:
                self.ExchangeMilitaryAchievements(9)
                return 0
        path=r"NPC选项\奇遇%02d.bmp"%n
        is_get = self.dm.SearchPngClick(75,247,230,310, "主线\奇遇空白0.bmp|主线\奇遇空白1.bmp|主线\奇遇空白2.bmp|主线\奇遇空白3.bmp|主线\奇遇空白4.bmp|主线\奇遇空白5.bmp", 0.95, 3, 0.1, 0, 0, 0)
        if is_get==1:
            is_get = self.AccessHomeNPC("奇遇")
            if is_get == 1:
                is_get = self.dm.SearchPngClick(474, 619, 921, 707, path, 0.8, 10, 0.03, 2, 20, 20)
                if is_get == 0:
                    return 0
                is_get = self.dm.SearchPngClick(160, 160, 1135, 539,r"主线\认主.bmp|主线\认主2.bmp|主线\认主3.bmp|主线\认主4.bmp|主线\认主暂无.bmp",
                                                0.9,1, 1, 0, 0, 0)
                if is_get == 1:
                    self.dm.KeyPressChar("f5")

                if n == 1:
                    self.DotaAttack(0, 0, 1180,299)
                    self.AdventureAttack()
                elif n == 2:
                    self.DotaAttack(0, 0, 973,105)
                    self.AdventureAttack()
                elif n == 3:
                    self.DotaAttack(0, 0, 806,56)
                    self.AdventureAttack()
                elif n == 4:
                    self.DotaAttack(0, 0, 1093, 60)
                    self.AdventureAttack()
                elif n == 5:
                    self.DotaAttack(101, 662, 778,518)
                    self.AdventureAttack()
                elif n == 6:
                    self.DotaAttack(27,633, 311,323)
                    self.AdventureAttack()
                elif n == 7:
                    print("换成6")
                    # self.DotaAttack(0, 0, 144, 359)
                    # time.sleep(3)
                    # self.AdventureAttack()
                elif n == 8:
                    self.DotaAttack(0, 0, 919,28)
                    self.AdventureAttack()
                elif n == 9:
                    self.DotaAttack(0, 0, 144, 359)
                    self.AdventureAttack()
                elif n == 10:
                    self.DotaAttack(0, 0, 1032, 117)
                    self.AdventureAttack()
                elif n == 11:
                    self.DotaAttack(0, 0, 299,59)
                    self.AdventureAttack()
                elif n == 12:
                    self.DotaAttack(99,631, 923,250)
                    self.AdventureAttack()

        else:
            is_get = self.dm.SearchPngClick(75, 247, 230, 310, "主线\奇遇带选择问号.bmp|主线\奇遇带选择问号1.bmp|主线\奇遇带选择问号2.bmp", 0.95, 3, 0.1, 1, 2, 2)
            if is_get == 1:
                is_get = self.dm.SearchPngClick(400, 516, 800, 548, "主线\稍后再选.bmp", 0.8, 60, 0.5, 0, 0, 0)
                self.GoSect()
                time.sleep(0.5)
                if is_get == 1:
                    return self.ChooseAdventure()
                else:
                    is_get = self.dm.SearchPngClick(400, 516, 800, 548, "主线\稍后再选.bmp", 0.8, 1, 0.5, 0, 0, 0)
                    self.GoSect()
                    if is_get == 1:
                        return self.ChooseAdventure()
        return 0

    def AdventureAttack(self):
        start = time.time()
        is_get = self.dm.SearchPngClick(400, 516, 800, 548, "主线\稍后再选.bmp", 0.8, 300, 0.1, 0, 0, 0)
        # todo
        if is_get !=1:
            self.GoSect()
            time.sleep(0.5)
        if is_get == 1:
            cost =time.time()-start
            print(cost)
            if cost < 10:
                self.data["奇遇难度"] += 1
            return self.ChooseAdventure()
        else:
            is_get = self.dm.SearchPngClick(400, 516, 800, 548, "主线\稍后再选.bmp", 0.8, 1, 0.1, 0, 0, 0)
            self.GoSect()
            if is_get == 1:
                cost = time.time() - start
                print(cost)
                if cost < 10:
                    self.data["奇遇难度"] += 1
                return self.ChooseAdventure()
            else:
                self.data["奇遇难度"] -= 1

    def PleaseEnemy(self,n):
        # n 0 刺客 1 内奸 2 杀手 3 卧底 4 心魔
        checkPath = r"NPC选项\请敌%s.bmp" % 0
        path = r"NPC选项\请敌%s.bmp" % n
        self.GoSect(num=2)
        self.dm.KeyPressChar("f1", num=2)
        if n==4:
            self.DotaBlink(0,0,643,235,1)

        res=self.AccessHomeNPC("请敌",flag=False)
        if res!=1:
            return 0
        res = self.dm.SearchPngClick(480, 630, 720, 710, checkPath, 0.9, 25, 0.05, 0, 0, 0)
        if res==0:
            return 0
        # 特殊情况跳过
        res = self.dm.SearchPngClick(480, 630, 720, 710, path, 0.9, 25, 0.05, 1, 5, 5)
        if res==0:
            return 1
        if  n==4:
            for i in range(5):
                res = self.dm.SearchPngClickEXn(300, 180, 960, 550, self.publicData["心魔挑战选择配置"], 0.9, 5, 0.1, 0, 0, 0)
                if res[0]!=-1:
                    time.sleep(0.2)
                    # self.log.info("开始截图心魔选择")
                    # self.GetXinMoPic()
                    # self.log.info("结束截图心魔选择")
                    time.sleep(0.2)
                    res = self.dm.SearchPngClickEXn(300, 180, 960, 550, self.publicData["心魔挑战选择配置"], 0.9, 1,
                                                    0.1, 1, 0, 0)

                    self.dm.LeftClick(634, 301, 1)
                    return 1

            return 0
    def PleaseXinMo(self,n):
        # n 0 刺客 1 内奸 2 杀手 3 卧底 4 心魔
        result=0
        self.log.info("打心魔")
        checkPath = r"NPC选项\请敌0.bmp"
        path = r"NPC选项\请敌4.bmp"

        res1 = self.AccessHomeNPC("请敌", flag=False)
        if res1 == 0:
            return 0
        # res2 = self.dm.SearchPngClick(480, 630, 720, 710, checkPath, 0.9, 25, 0.05, 0, 0, 0)

        for i in range(n):
            res=self.dm.SearchPngClick(480, 630, 720, 710, path, 0.9, 25, 0.05, 1, 5, 5)
            if res==0:
                res2 = self.dm.SearchPngClick(480, 630, 720, 710, checkPath, 0.9, 1, 0.05, 0, 0, 0)
                res1 = self.dm.SearchPngClick(480, 630, 720, 710, path, 0.9, 1, 0.05, 2, 5, 5)
                if res2==1 and res1==0:
                    self.data["当前心魔次数"] += 99
            if self.data["当前心魔次数"] >10:
                self.DotaBlink(0, 0, 643, 235, 1)
            for i in range(10):
                res = self.dm.SearchPngClickEXn(300, 180, 960, 550, self.publicData["心魔挑战选择配置"], 0.9, 5, 0.1, 0, 0,
                                            0)
                if res[0] != -1:
                    self.data["当前心魔次数"] += 1
                    time.sleep(0.2)
                    # self.log.info("开始截图心魔选择")
                    # self.GetXinMoPic()
                    # self.log.info("结束截图心魔选择")
                    res = self.dm.SearchPngClickEXn(300, 180, 960, 550, self.publicData["心魔挑战选择配置"], 0.9, 1,
                                                    0.1, 1, 0, 0)

                    self.dm.LeftClick(634, 301, 1)
                    result=1
                    if self.data["当前心魔次数"]>self.publicData["主c"]["心魔次数"]:
                        return result
                    break
        return result

    def UnlockMarrowCleansingSutra(self):
        self.log.info("开始解锁洗髓经")
        if self.publicData["主c"]["洗髓经残页品质"] == "红":
            return 1
        elif self.publicData["主c"]["洗髓经残页品质"] == "彩":
            is_get = self.AccessNPC(61, 661, 687, 239)

            if is_get == 1:
                path = "存档\洗髓经彩以激活.bmp|存档\洗髓经彩.bmp"
                is_get = self.dm.SearchPngClick(447, 619, 925, 714, path, 0.9, 10, 0.102, 2, 10, 10)
                if is_get != 1:
                    return 0
                path = "存档\洗髓经彩以激活.bmp"
                is_get = self.dm.SearchPngClick(447, 619, 925, 714, path, 0.9, 5, 0.102, 2, 10, 10)
                if is_get==1:
                    return 1
                path = "存档\洗髓经彩.bmp"
                is_get = self.dm.WaitPngDisappear(447, 619, 925, 714, path, 0.9, 10, 0.102, 2, 10, 10, is_wait=1)
                path = "存档\洗髓经彩以激活.bmp"
                is_get = self.dm.SearchPngClick(447, 619, 925, 714, path, 0.9, 5, 0.102, 2, 10, 10)
                if is_get == 1:
                    return 1

        else:
            return 1
        return 0


    def UnlockOther(self):
        self.log.info("开始购买重铸石，放下屠刀")
        tmp=[]
        if self.publicData["主c"]["是否购买重铸石"] :
            tmp.append("存档\重铸石.bmp")
        if self.publicData["主c"]["放下屠刀"] :
            tmp.append("存档\放下屠刀.bmp")
        if len(tmp)==0:
            return 1
        if self.publicData["主c"]["洗髓经残页品质"] == "彩":
            path = "存档\洗髓经彩.bmp"
            is_get = self.dm.WaitPngDisappear(447, 619, 925, 714, path, 0.9, 10, 0.102, 2, 10, 10, is_wait=1)


        is_get = self.AccessNPC(61, 661, 687, 239)
        path = "|".join(tmp)
        if is_get == 1:
            is_get = self.dm.WaitPngDisappear(447, 619, 925, 714, path, 0.9, 5, 0.102, 2, 10, 10, is_wait=1)
            if is_get == 0:
                return 1
        else:
            return 0

    def RMarrowCleansingSutra(self):
        is_get = self.dm.WaitPngDisappear(500, 300, 781, 348, "主线\融合洗髓经.bmp|主线\融合洗髓经_遮挡.bmp", 0.8, 1,
                                          0, 1, 221, 100)
        if len(self.data["需要的洗髓经残页"])==0 or len(self.data["需要r洗髓经残页位置"])==0:
            return 1
        time.sleep(0.2)
        i=self.data["需要r洗髓经残页位置"][0]
        colour=self.publicData["主c"]["洗髓经残页品质"]
        if self.publicData["基础配置"]["难度"]<8:
            colour="红"
        if colour=="彩":
            pathx = "主线\洗髓经\一键天彩.bmp|主线\洗髓经\一键天彩2.bmp"
        else:
            pathx = "主线\洗髓经\一键天胡.bmp|主线\洗髓经\一键天胡2.bmp"
        path = "|".join(self.data["需要的洗髓经残页"])
        path = self.dm.GetPicAbsPath(path)
        x1 = 765; y1 = 634;x2 = 800; y2 = 669
        if i == 1:
            x1, y1, x2, y2=765, 634, 800, 669
        elif i==2:
            x1, y1, x2, y2 = 800, 634, 835, 669
        elif i==3:
            x1, y1, x2, y2 = 730, 669, 765, 704
        elif i==4:
            x1, y1, x2, y2 = 765, 669, 800, 704
        elif i==5:
            x1, y1, x2, y2 = 800, 669, 835, 704
        res, x, y = self.dm.FindPicEx(x1, y1, x2, y2, path, "000000", 0.95)
        if res == -1:
            x=int((x1+x2)/2)
            y=int((y1+y2)/2)
            self.dm.RightClick(x, y, 1)
            is_get = self.dm.SearchPngClick(728, 600, 950, 720, pathx, 0.8, 15, 0.1, 1, 20, 8)
        else:
            path=self.data["需要的洗髓经残页"][res]
            path = self.dm.GetPicAbsPath(path)
            resx, x, y = self.dm.FindPicEx(x1, y1, x2, y2, path, "000000", 0.95)
            if resx==0:
                del self.data["需要的洗髓经残页"][res]
                del self.data["需要r洗髓经残页位置"][0]

        return 0

    # 升级洗髓经 todo 判断当前等级  怪物是否打死
    def UpgradeMarrowCleansingSutra(self):
        self.log.info("开始升级洗髓经")
        self.GoSect()
        self.dm.KeyPressChar("f1", num=2)
        time.sleep(0.3)
        path=r"存档\洗髓经1.bmp|存档\洗髓经2.bmp|存档\洗髓经3.bmp|存档\洗髓经4.bmp"
        path=self.dm.GetPicAbsPath(path)

        is_get = self.dm.SearchPngClick(732, 635, 746, 649, "存档\洗髓经z.bmp", 0.8, 1, 0.1, 0, 0, 0)
        is_get2 = self.dm.SearchPngClick(722, 623, 837, 705, "存档\空装备栏.bmp", 0.8, 1, 0, 0, 0, 0)
        if is_get==1 and is_get2==0:
            res,x,y=self.dm.FindPicEx(732, 635, 800, 700,path,"000000",0.8)
            if res==-1 or res == 3:
                if res == 3:
                    self.data["洗髓经当前等级"] = res
                self.dm.KeyPressChar("z")
                for i in range(10):
                    is_get = self.dm.SearchPngClick(500, 300, 781, 348, "主线\融合洗髓经.bmp|主线\融合洗髓经_遮挡.bmp", 0.8, 1, 0.25, 0, 0, 0)
                    if is_get == 1:
                        is_get=self.dm.WaitPngDisappear(500, 300, 781, 348, "主线\融合洗髓经.bmp|主线\融合洗髓经_遮挡.bmp", 0.8, 10, 0.25, 1, 221, 100)
                        if is_get==0:
                            self.data["洗髓经当前等级"] = 5
                            return 1
                    res,x, y = self.dm.FindPic(732, 635, 800, 700, path,"000000", 0.8)
                    if res !=-1:
                        break
            else:
                if res in [0,1,2]:
                    self.dm.KeyPressChar("z")
                self.data["洗髓经当前等级"]=res

        return 0


    # 升级洗髓经
    def MixMarrowCleansingSutra(self):
        self.GoSect()
        self.ClickSafe()
        self.dm.KeyPressChar("f1", num=2)
        time.sleep(0.3)
        is_get = self.dm.SearchPngClick(722, 623, 837, 705, "存档\空装备栏.bmp", 0.8, 1, 0, 0, 0, 0)
        if is_get==1 and  self.data["洗髓经当前等级"] == 5:
            return 1
        if self.data["洗髓经当前等级"] <5:
            self.UpgradeMarrowCleansingSutra()
            return -1
        elif self.data["洗髓经当前等级"] == 5:
            self.dm.KeyPressChar("z")
            for i in range(10):
                is_get = self.dm.SearchPngClick(500, 300, 781, 348, "主线\融合洗髓经.bmp|主线\融合洗髓经_遮挡.bmp", 0.8, 1, 0.25, 1, 41,
                                                100)
                if is_get == 1:
                    break
            for i in range(10):
                is_get = self.dm.SearchPngClick(722, 623, 837, 705, "存档\空装备栏.bmp", 0.8, 1, 0, 0, 0, 0)
                if is_get == 1:
                    return 1
                else:
                    time.sleep(1)

        return 0

    # 打船坞
    def AttackDock(self):
        # 可能会被击飞到路外面卡住
        self.log.info("主c打船坞")
        self.DotaAttack(74, 707, 463, 456)
        # 是否在boss5
        is_get = self.CheckPersonPosition(74, 707, 0.8, 1, 1, 371, 303, 600, 567)
        if is_get == 1:
            self.publicData["系统数据"]["船坞次数"] += 1
            return 1
        return 0
    # 打船坞
    def AttackGaoChangX(self):
        # 可能会被击飞到路外面卡住
        self.log.info("主c打高昌")
        self.DotaAttack(45, 660, 680, 300)
        # 是否在boss5
        is_get = self.CheckPersonPosition(45, 660, 0.8, 1, 1, 500, 100, 800, 500)
        if is_get == 1:
            self.publicData["系统数据"]["高昌次数"] += 1
            return 1
        return 0


    # 打聚贤庄
    def AttackJuXianVillage(self, n=30):
        self.log.info("打聚贤庄")
        x = 0
        if self.publicData["存档"]["聚贤庄"] == "快刀老六":
            x = 1
        elif self.publicData["存档"]["聚贤庄"] == "云中鹤":
            x = 2
        elif self.publicData["存档"]["聚贤庄"] == "铁面判官":
            x = 3
        elif self.publicData["存档"]["聚贤庄"] == "马夫人":
            x = 4
        elif self.publicData["存档"]["聚贤庄"] == "薛神医":
            x = 5
        for i in range(10):
            self.AccessNPC(73, 665, 755, 481)
            time.sleep(0.2)
            self.dm.LeftClick(500, 680, 1)
            is_get = self.CheckPersonPosition(103, 677, 0.8, 1, 1, 300, 100, 980, 620)
            if is_get == 1:
                break
        time.sleep(0.2)
        self.DotaAttack(98, 678, 1000, 17)
        time.sleep(0.2)
        self.AccessNPC(98, 678, 784, 422)
        for i in range(n):
            self.SurpriseDropConfirm()
            self.dm.LeftClick(457 + x * 43, 679, 1)
            is_get = self.dm.SearchPngClick(474, 470, 806, 536, "存档\挑战boss已经达上限.bmp", 0.8, 1, 0.5, 1, 0, 0)
            if is_get == 1:
                break


    # 只处理拿武器并返回
    def GetArm(self,main=True):
        # todo 此处调用不合适 返回也不对
        res=["绿", 8, 3000]
        # 主线
        if main:
            path0=self.data["第一次+1装备选择列表"]
            path=self.data["+1装备选择列表"]
        else:
            path0 = self.data["重铸选择列表"]
            path = self.data["重铸选择列表"]

        for i in range(1):
            self.dm.SearchPngClick(250, 400, 1200, 520,"主线\装备极品.bmp|主线\装备极品2.bmp|主线\装备极品3.bmp|主线\装备普通.bmp|主线\装备普通2.bmp|主线\装备普通3.bmp|主线\装备垃圾.bmp|主线\装备垃圾2.bmp|主线\装备垃圾3.bmp", 0.95, 10, 0.1, 0, 0,0)
            result = self.dm.SearchPngClickEXS(160, 220, 1200, 250, path0, 0.9, 3, 0.1, 1, 0, 0)
            if result != -1:
                result = self.GetRelativePath(result)
                if main:
                    for x in self.data["+1装备列表"]:
                        if x in result:
                            result = result.replace("普通","极品")
                self.log.info(result)
                if result in self.data["装备优先顺序字典"]:
                    res = [result,8,self.data["装备优先顺序字典"][result]]
                else:
                    res=[result, 8,200]
                break
            is_get = self.dm.SearchPngClick(584, 535, 698, 566, "主线\装备刷新.bmp|主线\装备刷新2.bmp", 0.8, 1, 0, 1, 10, 10)
            if is_get == 1:
                self.dm.SearchPngClick(250, 400, 1200, 520,  "主线\装备极品.bmp|主线\装备极品2.bmp|主线\装备极品3.bmp|主线\装备普通.bmp|主线\装备普通2.bmp|主线\装备普通3.bmp|主线\装备垃圾.bmp|主线\装备垃圾2.bmp|主线\装备垃圾3.bmp", 0.95, 10, 0.1, 0, 0, 0)
                self.GetArmPic()
            result = self.dm.SearchPngClickEXS(160, 220, 1200, 250, path, 0.9, 3, 0.1, 1, 0, 0)
            if result != -1:
                self.log.info(result)
                result = self.GetRelativePath(result)
                self.log.info(result)
                if main:
                    for x in self.data["+1装备列表"]:
                        if x in result:
                            result=result.replace("普通","极品")
                self.log.info(result)
                if result in self.data["装备优先顺序字典"]:
                    res = [result,8,self.data["装备优先顺序字典"][result]]
                else:
                    res=[result, 8,200]
                break
            # 其他红装
            is_get = self.dm.SearchPngClick(160, 220, 1200, 250,"装备\极品琴中剑.bmp", 0.9, 1, 0, 1, 0, 0)
            if is_get == 1:
                res=["极品琴中剑", 8, 500]
                break
            is_get = self.dm.SearchPngClick(250, 400, 1200, 520, "主线\装备极品.bmp|主线\装备极品2.bmp|主线\装备极品3.bmp", 0.9, 1, 0, 1, 0, 0)
            if is_get == 1:
                res=["红", 8, 500]
                break
            is_get = self.dm.SearchPngClick(160, 220, 1200, 250, "装备\普通琴中剑.bmp", 0.9, 1, 0, 1, 0, 0)
            if is_get == 1:
                res = ["普通琴中剑", 8, 1000]
                break
            is_get = self.dm.SearchPngClick(250, 400, 1200, 520, "主线\装备普通.bmp|主线\装备普通2.bmp|主线\装备普通3.bmp", 0.9, 1, 0, 1, 0, 0)
            if is_get == 1:
                res=["蓝", 8, 1000]
                break
            is_get = self.dm.SearchPngClick(160, 220, 1200, 250, "装备\垃圾琴中剑.bmp", 0.9, 1, 0, 1, 0, 0)
            if is_get == 1:
                res = ["垃圾琴中剑", 8, 2000]
                break
            is_get = self.dm.SearchPngClick(250, 400, 1200, 520, "主线\装备垃圾.bmp|主线\装备垃圾2.bmp|主线\装备垃圾3.bmp", 0.9, 1, 0, 1, 0, 0)
            res = ["绿", 8, 3000]
         # 防守时掉落的五鬼石会让点击无效
        is_get0 = self.dm.SearchPngClick(530, 300, 800, 430, "主线\获取洗髓经.bmp", 0.9, 5, 0.3, 1, 20, 90)
        time.sleep(0.5)

        is_get1 = self.dm.SearchPngClick(530, 300, 800, 430, "主线\获取洗髓经.bmp", 0.9, 1, 0.3, 2,
                                        20, 90)
        if is_get0==1 and is_get1==1 and self.publicData["是否回家过"]:
            self.GoSect()  # 防守时掉落的五鬼石会让点击无效
        is_get = self.dm.SearchPngClick(530, 300, 800, 430, "主线\获取洗髓经.bmp", 0.9, 1, 0.3, 1, 20, 90)
        if is_get==1:
            self.GoSect()  # 防守时掉落的五鬼石会让点击无效
            is_get = self.dm.SearchPngClick(530, 300, 800, 430, "主线\获取洗髓经.bmp", 0.9, 1, 0.3, 1, 20, 90)
        self.log.info(res)
        return res
    def CheckGetArm(self):
        path = "主线\装备垃圾.bmp|主线\装备普通.bmp|主线\装备极品.bmp|主线\装备垃圾2.bmp|主线\装备普通2.bmp|主线\装备极品2.bmp|主线\装备垃圾3.bmp|主线\装备普通3.bmp|主线\装备极品3.bmp"
        path = self.dm.GetPicAbsPath(path)
        is_get = self.dm.SearchPngClick(100, 90, 1200, 520, path, 0.95, 5, 0.5, 0, 0, 0)
        if is_get == 0:
            is_get = self.dm.SearchPngClick(100, 90, 1100, 145, "存档\小游戏取消.bmp", 0.8, 1, 0, 1, 10, 10)
            is_get = self.dm.SearchPngClick(530, 300, 800, 430, "主线\获取洗髓经.bmp", 0.9, 1, 0, 2, 170, 90)
            self.dm.LeftClick(641,590,1)
        else:
            return is_get
        if is_get == 0:
            is_get = self.dm.SearchPngClick(100, 90, 1100, 145, "存档\小游戏取消.bmp", 0.8, 1, 0, 1, 10, 10)
            is_get = self.dm.SearchPngClick(530, 300, 800, 430, "主线\获取洗髓经.bmp", 0.9, 1, 0, 2, 170, 90)
        else:
            return is_get
        is_get = self.dm.SearchPngClick(100, 90, 1200, 520, path, 0.8, 10, 0.5, 0, 0, 0)
        return is_get

    # 拿武器并处理 琴中剑 重拿
    def GetArms(self,new=True,main=True,n=0):
        self.log.info("kasss")
        self.dm.KeyPressChar("f1")
        is_get = self.CheckGetArm()
        self.log.info(is_get)
        if is_get==1:
            self.dm.MoveTo(800,20)
            is_get = self.dm.SearchPngClick(507, 293, 788, 375, "主线\是否获得装备.bmp", 0.9, 1, 0, 0, 0, 0)
            if is_get==1:
                self.dm.LeftClick(727,416,1)
                time.sleep(0.5)
            if new:
                self.GetArmPic()
            res=self.GetArm(main=main)
            arm_pic_path=res[0]
            self.log.info(len(self.data["武器装备"]))
            if new and main:
                self.data["武器装备"].append(res)
            elif main:
                self.data["武器装备"][-1]=res
            elif new is False and main is False:
                self.data["武器装备"][n][0] = res[0]
                self.data["武器装备"][n][2] = res[2]
            else:
                self.data["武器装备"][-1] = res
                self.log.error("预期外的情况·1")
            self.log.info(arm_pic_path)
            if "琴中剑"in res[0] :
                # and self.data["武器装备"][-1][1] >= 14
                self.log.info("琴中剑可能重拿")
                is_get = self.CheckGetArm()
                self.log.info(is_get)
                if is_get != 1:
                    self.dm.LeftClick(634, 585, 1)
                is_get = self.CheckGetArm()
                if is_get==1 and self.data["武器装备"][-1][1]>13 :
                    self.GetArms(new=False)
            elif self.publicData["主c"]["玄铁离别立即认主"] and("玄铁重剑"in arm_pic_path or "离别钩"in arm_pic_path) :
                # if n==0:
                #     self.ArmRecognizeLord(len(self.data["武器装备"])-1)
                # else:
                self.ArmRecognizeLord(n)
                res[2]=-1
            else:
                self.log.info("开始检查是否需要重铸")
                for name in self.publicData["主c"]["主动重铸列表"].split(","):
                    self.log.info(name)
                    if name in arm_pic_path:
                        self.log.info("开始重铸")
                        res=self.ArmRecast(len(self.data["武器装备"])-1)
                        # if res!=-1:
                        #     self.data["武器装备"][-1] = res
                        #     self.GoSect()  # 防守时掉落的五鬼石会让点击无效
                        #     is_get = self.dm.SearchPngClick(530, 300, 800, 430, "主线\获取洗髓经.bmp", 0.9, 5, 0.3, 2,
                        #                                     20, 90)
                        #     self.GoSect()  # 防守时掉落的五鬼石会让点击无效
                        #     is_get = self.dm.SearchPngClick(530, 300, 800, 430, "主线\获取洗髓经.bmp", 0.9, 1, 0.3, 2,
                        #                                     20, 90)
                        #     self.GoSect()  # 防守时掉落的五鬼石会让点击无效
                        #     is_get = self.dm.SearchPngClick(530, 300, 800, 430, "主线\获取洗髓经.bmp", 0.9, 1, 0.3, 2,
                        #                                     20, 90)
                        break
            return 1
        return 0
            # is_get = self.dm.SearchPngClick(530, 300, 800, 430, "主线\获取洗髓经.bmp", 0.9, 10, 0.3, 2, 20, 90)
            # is_get = self.dm.SearchPngClick(530, 300, 800, 430, "主线\获取洗髓经.bmp", 0.9, 1, 0.3, 2, 20, 90)
    # 重铸
    def ArmRecastAuto(self):
        self.log.info("开始批量重铸武器")
        is_get = self.dm.SearchPngClick(1000, 470, 1280, 644, "主线\重铸石不带数量.bmp", 0.8, 5, 0.2, 0, 0, 0)
        if is_get != 1:
            return [-1,"-1",-1]

        self.log.info("打印装备信息")
        self.log.info(self.data["武器装备"])

        n = 0
        if len(self.data["武器装备"])==0:
            return [-1,"-1",-1]
        for i in range(len(self.data["武器装备"])):
            if self.data["武器装备"][i][2] > self.data["武器装备"][n][2]:
                n = i
        res= self.ArmRecast(n)

        return res



    # 重铸
    def ArmRecast(self,n):
        self.log.info("开始重铸第%s个 (从0开始)"%n)
        if n==0:
            x, y = 747, 651
        elif n == 1:
            x, y = 782, 651
        elif n == 2:
            x, y = 817, 651
        elif n == 3:
            x, y = 747, 686
        elif n == 4:
            x, y = 782, 686
        else :
            x, y = 817, 686
        lv=self.data["武器装备"][n][1]
        is_get = self.dm.SearchPngClick(1000, 470, 1280, 644, "主线\重铸石不带数量.bmp", 0.8, 5, 0.2, 0, 0, 0)
        if is_get != 1:
            return -1
        for zz in range(10):
            self.dm.RightClick(x, y, 1)
            is_get = self.dm.SearchPngClick(700, 550, 1000, 720,"主线\重铸.bmp|主线\重铸2.bmp|主线\重铸3.bmp|主线\重铸4.bmp", 0.8, 5, 0.3, 1,5, 8)
            if is_get==1:
                time.sleep(0.5)
                break
        if is_get == 1:
            for i in range(10):
                res=self.GetArms(new=False,main=False,n=n)
                if res==1:
                    break
            return 1

        return -1

    # 装备认主 # 不适合拿取绝世神兵后
    def ArmRecognizeLord(self,i):
        # i 0-5
        self.log.info("开始认主武器%s"%i)
        self.data["武器开孔状态"][i] = True
        self.data["武器宝玉孔状态"][i] = True
        self.data["武器宝石孔状态"][i] = True
        for x in range(10):
            self.dm.KeyPressChar("f5")
            time.sleep(1)
            is_get = self.dm.SearchPngClick(160, 160, 1135, 539, "主线\认主.bmp|主线\认主2.bmp|主线\认主3.bmp|主线\认主4.bmp|主线\认主暂无.bmp", 0.9, 1, 0.3, 0, 0, 0)
            if is_get==1:
                break
        self.dm.LeftClick(244+i*162,513,1)
        self.dm.SearchPngClick(438, 370, 816, 450, "主线\洗髓经_确认.bmp|主线\洗髓经_确认2.bmp|主线\洗髓经_确认遮挡.bmp", 0.9, 6, 0.5, 0, 0, 0)
        self.dm.WaitPngDisappear(438, 370, 816, 450, "主线\洗髓经_确认.bmp|主线\洗髓经_确认2.bmp|主线\洗髓经_确认遮挡.bmp", 0.9, 6, 0.5, 1, 30, 10)

        for i in range(10):
            is_get = self.dm.SearchPngClick(160, 160, 1135, 539, r"主线\认主.bmp|主线\认主2.bmp|主线\认主3.bmp|主线\认主4.bmp|主线\认主暂无.bmp", 0.9,
                                            1, 0.3, 0, 0, 0)
            if is_get==1:
                self.dm.KeyPressChar("f5")
                time.sleep(3)
            else:
                break

    def UpgradeArmAuto(self,target=14):
        start_time = time.time()
        self.log.info(self.data["武器装备"])
        self.dm.KeyPressChar("f1",num=2)
        index=0
        min_lv=99
        self.log.info(self.data["武器装备"])
        for i in  range(len(self.data["武器装备"])):
            self.log.info(self.data["武器装备"])
            if self.data["武器装备"][i][1] <min_lv:
                min_lv=self.data["武器装备"][i][1]
                index=i
            self.log.info(i)
            self.log.info(index)
            self.log.info(min_lv)
        res = self.UpgradeArm(index, target)
        end_time = time.time()
        self.log.info("升级武器花费时间%s"%(end_time-start_time))
        return res


    def UpgradeArm(self,n,target=14):
        # n 第几把武器
        # target
        # -1 没铁了 1 成功升级  0未知 2升到14级
        if n>len(self.data["武器装备"])-1:
            return 2

        if  self.data["武器装备"][n][1] >= target:
            return 2
        if n==0:
            x, y = 747, 651
        elif n == 1:
            x, y = 782, 651
        elif n == 2:
            x, y = 817, 651
        elif n == 3:
            x, y = 747, 686
        elif n == 4:
            x, y = 782, 686
        else :
            x, y = 817, 686
        is_get = self.dm.SearchPngClick(1000, 470, 1280, 644, "主线\铁不带数量.bmp", 0.8, 5, 0.2, 0, 0, 0)
        is_get2 = self.dm.SearchPngClick(1000, 470, 1280, 644, "主线\铁1.bmp|主线\铁2.bmp|主线\铁3.bmp|主线\铁4.bmp", 0.9, 5, 0.2, 0, 0, 0)
        if is_get!=1:
            return -1
        elif is_get2==1 or target-self.data["武器装备"][n][1]<5:
            self.log.info("打印装备信息")
            self.log.info(self.data["武器装备"])
            self.log.info("开始升级第%s把武器+1" % n)
            self.dm.RightClick(x, y, 1)
            self.MoveSafe()
            time.sleep(0.2)
            is_get = self.dm.SearchPngClick(700, 550, 1000, 720,
                                            "主线\强化.bmp|主线\强化2.bmp|主线\强化3.bmp|主线\强化4.bmp", 0.8, 15, 0.1,
                                            1, 20, 8, is_wait=1)
            if is_get == 1:
                self.data["武器装备"][n][1] = self.data["武器装备"][n][1] + 1
                self.dm.LeftClick(327, 664, 1)
                if self.data["武器装备"][n][1] in [12,13,14, 15] and "琴中剑" in self.data["武器装备"][n][0]:
                    self.log.info("琴中剑可能升级重拿")
                    is_get = self.CheckGetArm()
                    if is_get != 1:
                        self.dm.LeftClick(634, 585, 1)
                    self.GetArms(new=False)
                return 1
            self.dm.LeftClick(327, 664, 1)
        else:
            self.log.info("开始升级第%s把武器+5" % n)
            self.dm.RightClick(x, y, 1)
            self.MoveSafe()
            time.sleep(0.2)
            is_get = self.dm.SearchPngClick(700, 550, 1000, 720, "主线\强化加5.bmp|主线\强化加52.bmp", 0.8, 15, 0.1,1, 20, 8, is_wait=1)
            if is_get == 1:
                self.data["武器装备"][n][1] = self.data["武器装备"][n][1] + 5
                self.dm.LeftClick(327, 664, 1)
                if self.data["武器装备"][n][1] in [12,13,14,15,16,17,18,19] and "琴中剑" in self.data["武器装备"][n][0]:
                    self.log.info("琴中剑可能升级重拿")
                    is_get = self.CheckGetArm()
                    if is_get != 1:
                        self.dm.LeftClick(634, 585, 1)
                    self.GetArms(new=False)
                return 1
            self.dm.LeftClick(327, 664, 1)
        return 0

    def GetArmsFast(self):
        path = "主线\装备垃圾.bmp|主线\装备普通.bmp|主线\装备极品.bmp|主线\装备垃圾2.bmp|主线\装备普通2.bmp|主线\装备极品2.bmp|主线\装备垃圾3.bmp|主线\装备普通3.bmp|主线\装备极品3.bmp"
        path = self.dm.GetPicAbsPath(path)
        is_get = self.dm.SearchPngClick(250, 400, 1200, 520, path, 0.95, 1, 0.5, 0, 0, 0)
        if is_get == 1:
            self.log.info("快速拿装备 只有卡了才会进入这个逻辑 或者防守")
            self.dm.MoveTo(800, 20)
            for i in range(1):
                is_get = self.dm.SearchPngClick(250, 400, 1200, 520, "主线\装备极品.bmp", 0.9, 1, 0, 1, 10, 0)
                if is_get == 1:
                    break
                is_get = self.dm.SearchPngClick(584, 535, 698, 566, "主线\装备刷新.bmp", 0.9, 1, 0, 1, 10, 10)
                if is_get == 1:
                    time.sleep(1)
                is_get = self.dm.SearchPngClick(250, 400, 1200, 520, "主线\装备极品.bmp", 0.9, 1, 0, 1, 10, 0)
                if is_get == 1:
                    break
                is_get = self.dm.SearchPngClick(250, 400, 1200, 520, "主线\装备普通.bmp", 0.9, 1, 0, 1, 10, 0)
                if is_get == 1:
                    break
                is_get = self.dm.SearchPngClick(250, 400, 1200, 520, "主线\装备垃圾.bmp", 0.9, 1, 0, 1, 0, 0)
            is_get = self.dm.SearchPngClick(530, 300, 800, 430, "主线\获取洗髓经.bmp", 0.9, 5, 0.3, 2, 20, 90)
            is_get = self.dm.SearchPngClick(530, 300, 800, 430, "主线\获取洗髓经.bmp", 0.9, 1, 0.3, 2, 20, 90)

    def ChoseLevel(self):
        # 没开30+难度的可能有问题
        lv = self.publicData["基础配置"]["难度"]
        mode = self.publicData["基础配置"]["模式"]
        self.log.info("选择难度 %s %s" % (lv, mode))
        n = 1
        z=1
        # 选择难度
        if lv <= 10:
            n = 1
            z= lv
        elif lv <= 20:
            n = 2
            z = lv-10
        elif lv <= 30:
            n = 3
            z = lv - 20
        else:
            n = 4
            z = lv - 30
        path = r"存档\门派\%s.bmp|存档\门派\%s_1.bmp" % (n, n)
        self.dm.SearchPngClick(500, 520, 800, 600, path, 0.8, 10, 0.5, 1, 3, 6)
        time.sleep(2)
        self.log.info("选择关卡")
        # self.dm.MoveTo(7, 7)
        self.dm.LeftClick(z * 113 + 17, 327, 3)
        # 默认就是普通，不查找
        if mode != "普通":
            path = r"存档\门派\%s.bmp" % mode
            self.dm.SearchPngClick(300, 550, 950, 680, path, 0.8, 5, 0.3, 1, 10, 5, is_wait=1)
            self.dm.SearchPngClick(300, 550, 950, 680, path, 0.8, 5, 0.3, 1, 20, 6, is_wait=1)
        time.sleep(0.5)
        self.dm.SearchPngClick(590, 636, 690, 680, "梦入江湖.bmp", 0.8, 5, 0.5, 1, 10, 10, is_wait=1)

    def CreateRoom(self):
        self.log.info("开始创建房间")
        res=self.dm.SendStringIme2(self.hwnd, "", 200)
        self.log.info(res)
        # 判断是否在游戏主页
        is_get = self.dm.SearchPngClick(892, 300, 1107, 600, "dota2\创建自定义房间.bmp", 0.8, 3, 1, 0, 0, 0)
        if is_get == 0:
            for j in range(3):
                self.dm.LeftClick(753, 19, 1)
                is_get=self.dm.SearchPngClick(300, 45, 500, 70, "dota2\游戏库0.bmp|dota2\游戏库1.bmp", 0.8, 30, 1, 0, 0, 0)
                if is_get==1:
                    break
            time.sleep(0.768)
            for i in range(100):
                # 点击游戏库
                if i%10==0:
                    self.dm.LeftClick(377, 56, 1)
                    self.dm.LeftClick(377, 56, 1)
                time.sleep(0.768)
                # 点击江湖
                is_get = self.dm.SearchPngClick(170, 100, 1088, 612, "dota2\江湖小图标.bmp", 0.8, 1, 0.5, 1, 40, 40)
                if is_get == 1:
                    break
                is_get = self.dm.SearchPngClick(170, 100, 1088, 612, "dota2\江湖小文字.bmp", 0.8, 1, 0.5, 1, 10, -10)
                if is_get == 1:
                    break
        self.log.info("开始创建房间")
        for i in range(60):
            self.log.info(i)
            time.sleep(1)
            is_get=self.dm.SearchPngClick(170, 100, 1088, 612, "dota2\江湖大图标.bmp", 0.8, 1, 0, 0, 0, 0)
            is_get2=self.dm.SearchPngClick(892, 300, 1107, 427, "dota2\创建自定义房间.bmp", 0.8, 1, 0, 0, 0, 0)
            if is_get==1 or is_get2==1:
                break
        self.dm.SearchPngClick(892, 300, 1107, 427, "dota2\创建自定义房间.bmp", 0.8, 10, 0.3, 1, 100, 10, is_wait=1)
        # 显示密码
        self.dm.LeftClick(463, 463, 1)
        self.ChooseServer(self.publicData["基础配置"]["服务器"])
        for i in range(5):
            time.sleep(0.3)
            self.dm.LeftClick(555, 446, 1)
        self.log.info("开始创建房间1")
        res= self.dm.KeyPressStr(self.publicData["基础配置"]["房间密码"], 60)
        self.log.info(res)

        time.sleep(0.722)
        self.log.info("开始创建房间2")
        self.dm.SearchPngClick(655, 550, 1090, 576, "dota2\确定创建自定义房间.bmp|dota2\确定创建自定义房间2.bmp",
                               0.8, 100, 1, 1, 15, 8, is_wait=1)
        for i in range(100):
            is_get=self.dm.SearchPngClick(1026, 527, 1090, 580, "dota2\房间密码.bmp",0.8, 1, 0, 0, 0,0)
            if is_get==1:
                return 1
            is_get = self.dm.SearchPngClick(1026, 527, 1090, 580, "dota2\房间公开.bmp", 0.8, 1, 0, 0, 0,0)
            if is_get == 1:
                return 0
            is_get = self.dm.SearchPngClick(500, 325, 750, 375, "dota2\接受开始.bmp|dota2\接受开始2.bmp", 0.8,  1, 0.5, 0, 0, 0)
            if is_get==1:
                return 1
            is_get = self.dm.SearchPngClick(450, 250, 900, 500, "dota2\收集延迟失败.bmp", 0.8, 1, 0, 1, 120, 90)
            if is_get==1:
                return 0
            if i>20:
                is_get=self.dm.SearchPngClick(892, 300, 1107, 427, "dota2\创建自定义房间.bmp", 0.8, 1, 0, 0, 0, 0)
                if is_get==1:
                    return 0
            time.sleep(1)
        return 0

    # 棋盘
    def ChallengeBoard(self,n):
        for i in range(3):
            res=self.AccessNPC(61, 666, 687, 231)
            if res==1:
                self.dm.LeftClick(495,678,2)
                res=self.DotaCheckAttackMove(53,634,602,543)
                if res==1:
                    for i in range(1):
                        time.sleep(n)
                        self.GoHome(step=0.5,num=10)
                        time.sleep(1)
                        self.GetArm2Pic()
                        res=self.dm.SearchPngClick(160, 220, 1200, 250,self.data["绝世神兵3"],  0.9, 3, 0.5, 1, 0, 0, is_wait=1)
                        if res ==1:
                            self.data["武学境界"] = 3
                            break
                        res = self.dm.SearchPngClick(160, 220, 1200, 250, self.data["绝世神兵2"], 0.9, 3, 0.5, 1, 0, 0,is_wait=1)
                        if res == 1:
                            self.data["武学境界"] = 2
                            break
                        res = self.dm.SearchPngClick(160, 220, 1200, 250, self.data["绝世神兵1"], 0.9, 3, 0.5, 1, 0, 0,
                                                     is_wait=1)
                        if res == 1:
                            self.data["武学境界"] = 1
                            break
                        else:
                            self.dm.LeftClick(517,316,1)
                            time.sleep(1)
                            self.dm.LeftClick(517, 316, 1)
                            self.data["武学境界"] = 1
                            break
                    self.dm.SearchPngClick(500, 397, 636, 438, "主线\洗髓经_确认.bmp|主线\洗髓经_确认2.bmp|主线\洗髓经_确认遮挡.bmp", 0.9, 5, 0.3, 2, 5, 5)
                    self.dm.SearchPngClick(500, 397, 636, 438, "主线\洗髓经_确认.bmp|主线\洗髓经_确认2.bmp|主线\洗髓经_确认遮挡.bmp", 0.9, 1, 0.3, 2, 5,  5)
                    return 1
        return 0

    def EatBook(self):
        self.log.info("检查主c吃书")
        now = time.time()
        if now - self.data["最近一次吃书"] < 30.0:
            return 0
        if self.publicData["系统"]["主要阶段"] =="存档":
            self.data["最近一次吃书"] = time.time()+99999.0
            return 0
        self.log.info("主c吃书")
        self.data["最近一次吃书"]=now
        path1=self.data["仓库上品书路径"]
        path2 = self.dm.GetPicAbsPath(self.data["上品书路径"])
        tmp=[]
        flag=False
        for i in range(5):
            res=self.GetPublicWarehouse(path1)
            if res!=1:
                self.log.info("没有书了")
                break
            else:
                flag = True
        if flag is False:
            return 0
        for i in range(10):
            res, x, y = self.dm.FindPicEx(996, 460, 1279, 646, path2, "000000", 0.9)
            if x > 0 and y > 0:
                tag="%s|%s"%(x,y)
                if tag in tmp:
                    time.sleep(1)
                    res, x, y = self.dm.FindPicEx(996, 460, 1279, 646, path2, "000000", 0.9)
                    tag2 = "%s|%s" % (x, y)
                    if tag == tag2:
                        self.dm.LeftClick(x + 5, y + 5, 2)
                else:
                    tmp.append(tag)
                    self.dm.LeftClick(x + 5, y + 5, 2)
            else:
                break
        self.log.info("主c吃书结束")
        self.PutIntoPublicWarehouse(r"书\6级藏宝图.bmp|书\7级藏宝图.bmp|书\9级藏宝图.bmp|书\10级藏宝图.bmp",n=1)
        self.MoveSafe()
    def GetGem(self,fource=False):
        self.log.info("检查主c拿宝石")
        now = time.time()

        if now - self.data["最近一次拿宝石"] < 60.0 and fource is False:
            return 0
        if self.publicData["系统"]["主要阶段"] =="存档":
            self.data["最近一次拿宝石"] = time.time()+99999.0
            return 0
        self.log.info("主c拿宝石")
        self.data["最近一次拿宝石"] = now
        self.GetPublicGem()

    def OpenArmPage(self):
        self.log.info("开始打开武器界面")

        is_open = False
        for x in range(3):
            self.dm.KeyPressChar("f5")
            time.sleep(0.1)
            is_get = self.dm.SearchPngClick(160, 160, 1135, 539,
                                            "主线\认主.bmp|主线\认主2.bmp|主线\认主3.bmp|主线\认主4.bmp|主线\认主暂无.bmp",
                                            0.95, 15, 0.1, 0, 0, 0)
            if is_get == 1:
                is_open = True
                break
        if is_open is False:
            return 0
        else:
            return 1
    def CloseArmPage(self):
        self.log.info("开始关闭武器界面")

        for i in range(5):
            self.dm.KeyPressChar("f5")
            for i in range(1):
                is_get = self.dm.SearchPngClick(160, 160, 1135, 539,
                                                r"主线\认主.bmp|主线\认主2.bmp|主线\认主3.bmp|主线\认主4.bmp|主线\认主暂无.bmp",
                                                0.9,
                                                5, 0.1, 0, 0, 0)
                if is_get == 0:
                    return 1
        return 0

    def PreciousGemAll(self,tag,n=20):
        self.log.info("开始镶嵌%s" % tag)
        # 是否用完

        x0 = 175
        for i in range(n):
            num = i % 6
            self.log.info(self.data["武器%s孔状态"%tag])
            self.log.info("开始给第%s把武器打%s" % (num,tag))
            if self.data["武器%s孔状态"%tag][num]:
                self.log.info("第%s把武器打%s" % (num,tag))
                continue
            res, x, y = self.dm.FindPicEx(x0 + 162 * num, 260, x0 + (162 * num) + 40, 482, self.data["武器%s"%tag],
                                          "000000", 0.9)
            if res == -1:
                self.data["武器%s孔状态"%tag][num] = True
                continue
            for i in range(3):
                self.dm.LeftClick(x + 5, y + 5, 1)
                is_get = self.dm.SearchPngClick(220, 180, 1000, 380, "主线\宝石背包.bmp", 0.9, 30, 0.1, 0, 0, 0 )
                if is_get ==1:
                    res = self.PreciousGem()
                    if res == 1:
                        time.sleep(0.3)
                        break
                    elif res == -1:
                        return -1
                    break
        return 0

    def UseDrillingStone(self,n=20):
        # 左边的2把武器可能被 左边提示挡住
        self.GoHome(num=3)
        for i in range(3):
            res=self.OpenArmPage()
            if res == 1:
                break
        x0 = 175
        num = self.GetValueIndex(self.data["武器开孔状态"], False)
        if num != -1:
            self.log.info("开始使用融金石")
            for i in range(n):
                num=i%6
                self.log.info("开始给第%s把武器开孔" % num)
                if self.data["武器开孔状态"][num]:
                    self.log.info("第%s把武器以开孔" % num)
                    continue
                res, x, y = self.dm.FindPicEx(x0 + 162 * num, 260, x0 + (162 * num) + 40, 482, self.data["武器未解锁孔"],
                                              "000000", 0.9)
                if res != -1:
                    # 取放逻辑需加优化 校验
                    self.dm.LeftClick(x + 5, y + 5, 1)
                    is_get = self.dm.SearchPngClick(530, 397, 626, 435,
                                                    "主线\洗髓经_确认.bmp|主线\洗髓经_确认2.bmp|主线\洗髓经_确认遮挡.bmp",
                                                    0.9,
                                                    30, 0.1, 1, 5, 5, is_wait=1)
                    if is_get == 1:
                        time.sleep(0.2)
                # else:
                #     self.data["武器开孔状态"][num] = True
        flag1 = self.PreciousGemAll("宝石")
        flag2 = self.PreciousGemAll("宝玉")
        if  (flag1 == -1 or flag2 == -1) and self.publicData["系统"]["主要阶段"] in ["等待","发育"]:
            self.log.info("开始购买宝石")
            for i in range(3):
                res = self.CloseArmPage()
                if res == 1:
                    break
            for i in range(3):
                res=self.AccessCarryNPC("游商")
                if res==1:
                    break

            for i in range(15):
                self.dm.LeftClick(721,681,2)
                self.SurpriseDropConfirm()
                if self.OcrSuiYinNum() < 300000:
                    break
            for i in range(3):
                res = self.OpenArmPage()
                if res == 1:
                    break
            flag1 = self.PreciousGemAll("宝石",n=12)
            flag2 = self.PreciousGemAll("宝玉",n=12)


        self.log.info("开始认主")
        for i in range(6):
            is_get = self.dm.SearchPngClick(530, 397, 626, 435,
                                            "主线\洗髓经_确认.bmp|主线\洗髓经_确认2.bmp|主线\洗髓经_确认遮挡.bmp",
                                            0.9, 3, 0.1, 1, 5, 5)
            if is_get==1:
                time.sleep(0.2)
            is_get = self.dm.SearchPngClick(160, 160, 1135, 539,
                                            r"主线\认主.bmp|主线\认主2.bmp|主线\认主3.bmp|主线\认主4.bmp|主线\认主暂无.bmp",
                                            0.9, 5, 0.1, 1, 5, 5)
            if is_get !=1:
                break
            time.sleep(0.2)
            is_get = self.dm.SearchPngClick(530, 397, 626, 435,
                                            "主线\洗髓经_确认.bmp|主线\洗髓经_确认2.bmp|主线\洗髓经_确认遮挡.bmp",
                                            0.9, 15, 0.1, 1, 5, 5)
            if is_get == 1:
                time.sleep(0.2)
        for i in range(3):
            res=self.CloseArmPage()
            if res == 1:
                break
        is_get = self.dm.SearchPngClick(1024, 650, 1122, 680, "存档\宝石\一键合成.bmp|存档\宝石\一键合成2.bmp",
                                        0.9, 3, 0.1, 1, 2, 2)
        is_get = self.dm.SearchPngClick(1024, 650, 1122, 680, "存档\宝石\一键合成.bmp|存档\宝石\一键合成2.bmp",
                                        0.9, 3, 0.1, 1, 2, 2)

    def PreciousGem(self, path=""):
        if path == "":
            path = self.GetNeedGemPath()
            path = self.dm.GetPicAbsPath(path)
        else:
            path = self.dm.GetPicAbsPath(path)

        for i in range(5):
            res, x, y = self.dm.FindPicExS(180, 216, 1163,548, path, "000000", 0.9)
            if x > 0 and y > 0:
                self.log.info("找到宝石 %s " % res)
                self.dm.LeftClick(x + 6, y + 5,2)
                self.MoveSafe()
                is_get = self.dm.SearchPngClick(180, 400, 1100, 590,r"主线\确认镶嵌.bmp|主线\确认镶嵌2.bmp",0.9,5, 0.1, 1, 5, 5)
                if is_get==1:
                    res = self.GetRelativePath(res, "pic")
                    self.log.info("宝石相对路径 %s " % res)
                    for tmp in self.data["宝石优先顺序列表"]:
                        if tmp[0] == res:
                            tmp[1] = tmp[1] - 1
                    return 1
                else:
                    return 0
        return -1

    def BuyDrillingStone(self):
        if self.get_main_stage() == "存档":
            return
        self.log.info("开始购买融金石")
        if self.GetValueIndex(self.data["武器开孔状态"], False) == -1:
            return 1
        res = self.AccessCarryNPC("文秀")
        if res != 1:
            return 0
        res = self.dm.SearchPngClick(478, 652, 837, 701,
                                     r"主线\高昌外区.bmp|主线\高昌深处.bmp|主线\文秀_大队集结令.bmp|主线\文秀_兑换融金石.bmp",
                                     0.9, 30, 0.1, 0, 10, 10)
        if res ==1:
            self.dm.SearchPngClick(478, 652, 837, 701, r"主线\文秀_兑换融金石.bmp", 0.9, 1, 0.03, 50, 5, 5)

    def DoSupTask10(self):
        self.log.info("开始打10书")
        check_path = self.dm.GetPicAbsPath("|".join(self.data["任务"]["10全"]))

        self.log.info("移动到目标10-1")
        res = self.DotaCheckMoveAttack(38, 659, 400, 353)
        if self.publicData["是否回家过"] or self.publicData["是否回门派过"]:
            return
        # time1 = time.time()
        # self.BuyDrillingStone()
        # time2 = time.time()
        cost_time = 0
        # self.log.info("购买融金石耗时%s" % cost_time)
        if cost_time < 3.0:
            time.sleep(3-cost_time)
        if self.publicData["是否回家过"] or self.publicData["是否回门派过"]:
            return
        self.PickUp(38, 659, 400, 362)
        if self.publicData["是否回家过"] or self.publicData["是否回门派过"]:
            return
        self.dm.KeyPressChar("f1", num=2)
        self.log.info("移动到目标10-2")
        res = self.DotaCheckMoveAttack(38, 654, 400, 500)
        if self.publicData["是否回家过"] or self.publicData["是否回门派过"]:
            return
        time.sleep(3)
        self.PickUp(0, 0, 400, 362)
        if self.publicData["是否回家过"] or self.publicData["是否回门派过"]:
            return 
        self.dm.KeyPressChar("f1", num=2)
        self.log.info("查找是否有书")
        for i in range(3):
            is_get = self.dm.SearchPngClick(992, 460, 1280, 650, r"书\挑战令10冰蛛.bmp|书\挑战令10机关猿.bmp|书\挑战令10邪教屠神.bmp", 0.9, 3, 0.1, 2, 5, 5)
            if is_get ==0:
                break
        is_get = self.dm.SearchPngClick(992, 460, 1280, 650, check_path, 0.9, 5, 0.1, 0, 0, 0)
        if is_get == 1:
            for i in range(len(self.data["任务"]["10"])):
                self.MoveMouseSafe()
                time.sleep(0.5)
                self.log.info(self.data["任务"]["10"])
                if len(self.data["任务"]["10"]) != 0:
                    taskPath = self.dm.GetPicAbsPath("|".join(self.data["任务"]["10"]))
                else:
                    break
                res, x, y = self.dm.FindPicEx(996, 460, 1279, 646, taskPath, "000000", 0.9)
                if res != -1:
                    # 取放逻辑需加优化 校验
                    self.dm.LeftClick(x+5,y+5,2)
                    del self.data["任务"]["10"][res]
                    self.PutIntoPublicWarehouse(r"书\10级藏宝图.bmp", n=1)
                else:
                    break
            self.SellingCheats(check_path)
            return 1
        return  0

        # 高昌 如果在高昌不进行其他操作
    def UnlockBoss10(self):
        self.log.info("检查解锁10上")
        num=self.OcrGuBiNum()
        if num <= 1000:
            return 0
        if self.data["任务"]["10冰蛛开启"] and self.data["任务"]["10机关猿开启"] and self.data["任务"]["10邪教屠神开启"]:
            return 0
        now = time.time()
        if now - self.data["最近一次解锁10"] < 22.0:
            return 0
        self.log.info("解锁10")
        self.data["最近一次解锁10"] = now
        res = self.DotaCheckMoveAttack(38, 656, 500, 373)
        if res==1:
            self.AccessNPC(40, 655, 423, 253)
            if self.data["任务"]["10冰蛛开启"] is False:
                self.dm.LeftClick(586,682,2)
                self.data["任务"]["10冰蛛开启"]=True
            elif self.data["任务"]["10机关猿开启"] is False:
                self.dm.LeftClick(722,681,2)
                self.data["任务"]["10机关猿开启"]=True
            elif self.data["任务"]["10邪教屠神开启"] is False:
                self.dm.LeftClick(851,683,2)
                self.data["任务"]["10邪教屠神开启"]=True
            return 1

    def PreAdvance(self):
        for i in range(5):
            res=self.XiuLian(13)
            if res > 13:
                break
        check_path = self.dm.GetPicAbsPath("|".join(self.data["任务"]["10全"]))
        self.SellingCheats(check_path)
        self.BuyDrillingStone()
        if self.data["是否卡丹"] is False:
            res = self.StuckBug2()
            if res == 1:
                self.data["是否卡丹"] = True
                self.dm.KeyPressChar("f1", num=2)
        if self.publicData["主c"]["奇遇前是否先断脉"]:
            for i in range(5):
                if self.data["当前战功兑换层数"] < 9:
                    self.ExchangeMilitaryAchievements(9)
                else:
                    break
        self.GetGem(fource=True)
        self.UseDrillingStone()
        self.XiuLian(15)
        self.XiuLian(15)
        self.data["奇遇前准备完成"] = True

    def ChooseServer(self,name):
        if name == "" or name == "最佳选择":
            return
        # site_map={
        #     "美国西部":1,
        #     "美国东部":2,
        #     "欧洲西部":3,
        #     "新加坡":4,
        #     "迪拜":5,
        #     "斯德哥尔摩":6,
        #     "巴西":7,
        #     "奥地利":8,
        #     "澳大利亚":9,
        #     "南非":10,
        #     "智利":11,
        #     "秘鲁":12,
        #     "阿根廷":13,
        #     "印度":14,
        #     "日本":15,
        #
        # }
        path = r"dota2\server\\" + name + ".bmp"
        for i in range(3):
            self.dm.LeftClick(675,316)
            is_get = self.dm.SearchPngClick(458, 333, 689, 651, r"dota2\server\背景.bmp", 0.95, 3, 1, 0, 0, 0)
            if is_get ==1:
                break
        self.dm.MoveTo(523, 454)
        self.dm.WheelDown(15)
        self.dm.MoveTo(438, 187)
        is_get = self.dm.SearchPngClick(458, 333, 541, 651,path, 0.95, 3, 1, 1, 5, 2)
        time.sleep(0.5)
        self.dm.LeftClick(522,642)